예제 #1
0
// Populate the selected database with the data scraped from the term URL.
func PopulateDB(termURL, ip, port, dbName, collectionName string) error {
	scrapeDB := db.New(ip, port, dbName, collectionName)

	err := scrapeDB.Init()
	if err != nil {
		return err
	}

	log.Debug("purging database")
	scrapeDB.Purge()

	term, err := scrape.GetXML(termURL)

	courseChan := make(chan types.Class)

	go scrape.DigestAll(term, courseChan)

	for class := range courseChan {
		err = scrapeDB.Put(class)
		if err != nil {
			return err
		}
	}

	log.Debug("finished populating database")

	return nil
}
예제 #2
0
	"github.com/scheedule/coursestore/api"
	"github.com/scheedule/coursestore/db"
)

var serveAPI *api.API

// Main command to be executed. Serves coursestore endpoint.
var serveCmd = &cobra.Command{
	Use:   "serve",
	Short: "Serve Course Endpoint",
	Long:  "Start serving course data via routes /lookup and /all",
	Run: func(cmd *cobra.Command, args []string) {
		initializeConfig()

		// Create DB Object
		serveDB := db.New(dbHost, dbPort, database, collection)
		err := serveDB.Init()
		if err != nil {
			log.Fatal("Failed to initialize database connection:", err)
		}

		// API Object
		serveAPI = api.New(serveDB)

		// Router
		r := mux.NewRouter()

		// All classes
		r.HandleFunc("/lookup", serveAPI.HandleAll)

		// All classes in department
예제 #3
0
func init() {
	testDB := db.New(os.Getenv("DB_HOST"), os.Getenv("DB_PORT"), os.Getenv("DB_NAME"), os.Getenv("DB_COLLECTION"))
	testDB.Init()
	testAPI = New(testDB)
}