2022-04-02 12:05:32 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
//"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
|
|
|
|
|
|
"github.com/jtom38/newsbot/collector/routes"
|
|
|
|
"github.com/jtom38/newsbot/collector/database"
|
|
|
|
"github.com/jtom38/newsbot/collector/services"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-04-17 07:25:49 -07:00
|
|
|
var err error
|
2022-04-02 12:05:32 -07:00
|
|
|
//EnableScheduler()
|
2022-04-17 07:25:49 -07:00
|
|
|
//dc := database.NewDatabaseClient()
|
|
|
|
//err := dc.Diagnosis.Ping()
|
|
|
|
//if err != nil { log.Fatalln(err) }
|
2022-04-02 12:05:32 -07:00
|
|
|
|
2022-04-17 07:25:49 -07:00
|
|
|
//CheckReddit()
|
|
|
|
CheckYoutube()
|
2022-04-02 12:05:32 -07:00
|
|
|
|
|
|
|
app := chi.NewRouter()
|
|
|
|
app.Use(middleware.Logger)
|
|
|
|
app.Use(middleware.Recoverer)
|
|
|
|
|
|
|
|
//app.Mount("/swagger", httpSwagger.WrapHandler)
|
|
|
|
app.Mount("/api", routes.RootRoutes())
|
|
|
|
|
|
|
|
log.Println("API is online and waiting for requests.")
|
|
|
|
log.Println("API: http://localhost:8081/api")
|
|
|
|
//log.Println("Swagger: http://localhost:8080/swagger/index.html")
|
|
|
|
err = http.ListenAndServe(":8081", app)
|
|
|
|
if err != nil { log.Fatalln(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func CheckReddit() {
|
|
|
|
dc := database.NewDatabaseClient()
|
|
|
|
sources, err := dc.Sources.FindBySource("reddit")
|
|
|
|
if err != nil { log.Println(err) }
|
|
|
|
|
2022-04-17 07:25:49 -07:00
|
|
|
rc := services.NewRedditClient(sources[0].Name, sources[0].ID)
|
2022-04-02 12:05:32 -07:00
|
|
|
raw, err := rc.GetContent()
|
|
|
|
if err != nil { log.Println(err) }
|
|
|
|
|
2022-04-07 14:53:40 -07:00
|
|
|
redditArticles := rc.ConvertToArticles(raw)
|
|
|
|
|
|
|
|
for _, item := range redditArticles {
|
|
|
|
_, err = dc.Articles.FindByUrl(item.Url)
|
|
|
|
if err != nil {
|
|
|
|
err = dc.Articles.Add(item)
|
|
|
|
if err != nil { log.Println("Failed to post article.")}
|
|
|
|
}
|
2022-04-02 12:05:32 -07:00
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func CheckYoutube() {
|
|
|
|
// Add call to the db to request youtube sources.
|
|
|
|
|
|
|
|
// Loop though the services, and generate the clients.
|
|
|
|
yt := services.NewYoutubeClient(0, "https://www.youtube.com/user/GameGrumps")
|
|
|
|
yt.CheckSource()
|
2022-04-02 12:05:32 -07:00
|
|
|
}
|