aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
blob: 20a1262a7f86bcd42bba51e4d3d02a1bd1548e0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main

import (
	"fmt"
	"adammathes.com/neko/config"
	"adammathes.com/neko/crawler"
	"adammathes.com/neko/importer"
	"adammathes.com/neko/models"
	"adammathes.com/neko/models/feed"
	"adammathes.com/neko/web"
	"log"
	"os"
)

func main() {
	// TODO: change this
	config.Read("./config.json")

	models.InitDB(config.Config.DBServer)
	if len(os.Args) < 2 {
		fmt.Printf("usage: neko [web|addfeed|crawl]\n")
		fmt.Printf("addfeed <url> -- add a new feed from <url>\n")
		return
	}
	cmd := os.Args[1]
	switch cmd {
	case "web":
		log.Printf("starting web server at %s", config.Config.WebServer)
		web.Serve()
	case "addfeed":
		addFeed()
	case "crawl":
		crawl()
	case "import":
		importLegacy()
	default:
		panic("not a valid command")
	}
}

func addFeed() {
	if len(os.Args) < 2 {
		log.Fatal("need a valid url")
	}
	url := os.Args[2]
	feed.NewFeed(url)
}

func importLegacy() {
	json_file := os.Args[2]
	log.Printf("importing json file from: %s", json_file)
	importer.ImportJSON(json_file)
}

func crawl() {
	crawler.Crawl()
}