mirror of
https://github.com/carlostrub/sisyphus
synced 2024-10-31 09:20:15 +00:00
create database
This commit is contained in:
parent
ceda4054c7
commit
88a68aacb8
68
database.go
Normal file
68
database.go
Normal file
@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/boltdb/bolt"
|
||||
)
|
||||
|
||||
// openDB creates and opens a new database and its respective buckets (if required)
|
||||
func openDB(path string) (db *bolt.DB, err error) {
|
||||
|
||||
// Open the sisyphus.db data file in your current directory.
|
||||
// It will be created if it doesn't exist.
|
||||
db, err = bolt.Open(path, 0600, nil)
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
|
||||
// Create DB bucket for the map of processed e-mail IDs
|
||||
err = db.Update(func(tx *bolt.Tx) error {
|
||||
_, err := tx.CreateBucketIfNotExists([]byte("Processed"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
|
||||
// Create DB bucket for word lists
|
||||
err = db.Update(func(tx *bolt.Tx) error {
|
||||
_, err := tx.CreateBucketIfNotExists([]byte("Wordlists"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
|
||||
// Create DB bucket for Junk inside bucket Wordlists
|
||||
err = db.Update(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket([]byte("Wordlists"))
|
||||
_, err := b.CreateBucketIfNotExists([]byte("Junk"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
|
||||
// Create DB bucket for Junk inside bucket Wordlists
|
||||
err = db.Update(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket([]byte("Wordlists"))
|
||||
_, err := b.CreateBucketIfNotExists([]byte("Good"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
12
filter_test.go
Normal file
12
filter_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
. "github.com/carlostrub/sisyphus"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Filter", func() {
|
||||
|
||||
})
|
6
glide.lock
generated
6
glide.lock
generated
@ -1,6 +1,8 @@
|
||||
hash: 05d37c1ae8f818b05d066dce22d2e3fa625b8cce35ddfe4d746eaf49b11320b2
|
||||
updated: 2017-03-10T19:22:40.441940049Z
|
||||
hash: 278ebf659dc6f1d5de92408300483b75e76c9f5d81febc25b83bfc585d7457ad
|
||||
updated: 2017-03-10T22:33:54.628681045Z
|
||||
imports:
|
||||
- name: github.com/boltdb/bolt
|
||||
version: 583e8937c61f1af6513608ccc75c97b6abdf4ff9
|
||||
- name: github.com/jbrukh/bayesian
|
||||
version: bf3f261f9a9c61145c60d47665b0518cc32c774f
|
||||
- name: github.com/kennygrant/sanitize
|
||||
|
@ -3,6 +3,8 @@ import:
|
||||
- package: github.com/jbrukh/bayesian
|
||||
- package: github.com/kennygrant/sanitize
|
||||
- package: github.com/luksen/maildir
|
||||
- package: github.com/boltdb/bolt
|
||||
version: ^1.3.0
|
||||
testImport:
|
||||
- package: github.com/onsi/ginkgo
|
||||
- package: github.com/onsi/gomega
|
||||
|
21
main.go
21
main.go
@ -13,22 +13,29 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get the Maildir to be handled
|
||||
|
||||
// Get the Maildir to be handled and the DB
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return log.Fatalf("get working directory: %s", err)
|
||||
}
|
||||
maildir := flag.String("d", wd+"/Maildir", "Path of the Maildir to be handled")
|
||||
maildir := flag.String("maildir", wd+"/Maildir", "Path to the Maildir")
|
||||
database := flag.String("database", wd+"/sisyphus.db", "Path to the sisyphus database")
|
||||
flag.Parse()
|
||||
|
||||
// Load the Maildir content
|
||||
// Load the Maildir
|
||||
mails, err := Index(*maildir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return log.Fatalf("load Maildir content: %s", err)
|
||||
}
|
||||
|
||||
fmt.Println(mails)
|
||||
|
||||
// Create a classifier
|
||||
//classifier := bayesian.NewClassifier(Good, Junk)
|
||||
// Open the database
|
||||
db, err := openDB("sisyphus.db", 0600, nil)
|
||||
if err != nil {
|
||||
return log.Fatalf("open database: %s", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user