From f0ea7f4a413697191040f774ced6164b5b71355d Mon Sep 17 00:00:00 2001 From: Fernando <100nandoo@gmail.com> Date: Sat, 3 Feb 2024 16:44:34 +0800 Subject: [PATCH] Remove rss --- config/config.go | 3 +- docs/index.md | 1 - docs/rss.md | 47 ----------------------------- main.go | 5 +--- rss/app.go | 77 ------------------------------------------------ rss/supabase.go | 64 ---------------------------------------- rss/telegram.go | 35 ---------------------- 7 files changed, 2 insertions(+), 230 deletions(-) delete mode 100644 docs/rss.md delete mode 100644 rss/app.go delete mode 100644 rss/supabase.go delete mode 100644 rss/telegram.go diff --git a/config/config.go b/config/config.go index 9400926..ca4f014 100644 --- a/config/config.go +++ b/config/config.go @@ -4,5 +4,4 @@ const SupabaseUrl, SupabaseKey string = "SUPABASE_URL", "SUPABASE_KEY" const TelegramBot string = "TELEGRAM_BOT" const TelegramDebug string = "TELEGRAM_CHANNEL_DEBUG" const TelegramFreeGames string = "TELEGRAM_CHANNEL_FREE_GAMES" -const TelegramRemoteOk string = "TELEGRAM_CHANNEL_REMOTE_OK" -const TelegramRss string = "TELEGRAM_CHANNEL_RSS" +const TelegramRemoteOk string = "TELEGRAM_CHANNEL_REMOTE_OK" \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 3316319..d743e17 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,4 +3,3 @@ My personal Go Telegram Bot [Free Games on :simple-steam::simple-epicgames:](freegames.md){ .md-button } [Remote :ok:](freegames.md){ .md-button } -[Rss :material-rss:](rss.md){ .md-button } diff --git a/docs/rss.md b/docs/rss.md deleted file mode 100644 index b865c0e..0000000 --- a/docs/rss.md +++ /dev/null @@ -1,47 +0,0 @@ -# Rss Feed -Rss Feed Bot - -## ❔ How it Works -```mermaid -flowchart LR - A --> B - B --> C - - - A[(Supabase)] - B(Filter) - C(Send to Telegram) -``` - - -1. `Supabase` ➡️ Get All Feeds from Supabase Db - -2. `Filter` ➡️ Keep items that is not older than 7 days ago - -3. `Send to Telegram` ➡️ Send Rss item(s) to Telegram Channel as a Bot - -``` -Run every Saturday at 11.05 AM -``` - -## 🛠️ Setup -### Environment Variables -| Name | Desc | -|----------------------|------------------------| -| TELEGRAM_BOT | Telegram bot API Token | -| TELEGRAM_CHANNEL_RSS | Telegram Channel id | -| SUPABASE_URL | Supabase URL | -| SUPABASE_KEY | Supabase Key | - -### Supabase Table Definition -```sql -create table - public.Rss ( - url text not null default ''::text, - name text not null default ''::text, - priority bigint not null default '0'::bigint, - category text not null default ''::text, - constraint Rss_pkey primary key (url), - constraint Rss_url_key unique (url) - ) tablespace pg_default; -``` \ No newline at end of file diff --git a/main.go b/main.go index 07330fe..5730b74 100644 --- a/main.go +++ b/main.go @@ -5,18 +5,15 @@ import ( "gobot/freegames/app" "gobot/pkg" "gobot/remoteok" - "gobot/rss" ) func main() { - fmt.Println("Gobot v1.4 started...") + fmt.Println("Gobot v1.5 started...") app.Scouting() app.Cleaning() remoteok.Scouting() remoteok.Cleaning() - rss.Scouting() - pkg.StartBlocking() } diff --git a/rss/app.go b/rss/app.go deleted file mode 100644 index 8960cb1..0000000 --- a/rss/app.go +++ /dev/null @@ -1,77 +0,0 @@ -package rss - -import ( - "fmt" - "github.com/mmcdole/gofeed" - "gobot/pkg" - "sync" -) - -// Get Rss feed from remote Ok API. It will return array of Item -func getRssItems(rss SupabaseRss) ([]*gofeed.Item, error) { - feed, err := pkg.Parser.ParseURL(rss.Url) - if err != nil { - fmt.Println("Error calling getRssItems", err) - return nil, err - } - return feed.Items, nil -} - -/* -Filter function for Rss Feed. -Keep only item not is not older than 7 days ago -*/ -func filter(items []*gofeed.Item) *[]gofeed.Item { - var result []gofeed.Item - sevenDaysAgo := pkg.DaysUnix(-7) - - for _, item := range items { - if item.PublishedParsed.Unix() > sevenDaysAgo { - result = append(result, *item) - } - } - return &result -} - -/* -getItemsAndFilter -Get Jobs from remote Ok API, after that applied filter -*/ -func getItemsAndFilter(supabaseRss SupabaseRss) *[]gofeed.Item { - result := make([]gofeed.Item, 0) - - items, err := getRssItems(supabaseRss) - - if err != nil { - fmt.Println("Error calling getRssItems", err) - return nil - } - result = *filter(items) - - return &result -} - -func Scouting() { - pkg.EverySaturdayDayAtThisHour(func() { - var wg sync.WaitGroup - var result []gofeed.Item - - fmt.Println("Scouting Rss") - rss := GetAllSupabaseRss() - - fmt.Println("rss", rss) - for _, supabaseRss := range rss { - wg.Add(1) - supabaseRss := supabaseRss - go func() { - defer wg.Done() - result = append(result, *getItemsAndFilter(supabaseRss)...) - }() - } - wg.Wait() - - for _, item := range result { - SendRssItem(item) - } - }, "11:05") -} diff --git a/rss/supabase.go b/rss/supabase.go deleted file mode 100644 index a89e85f..0000000 --- a/rss/supabase.go +++ /dev/null @@ -1,64 +0,0 @@ -package rss - -import ( - "fmt" - "github.com/mmcdole/gofeed" - "gobot/pkg" -) - -type SupabaseRss struct { - Url string `json:"url"` - Name string `json:"name"` - Priority int `json:"priority"` - Category string `json:"category"` -} - -const dbName = "Rss" - -/* -GetAllSupabaseRss - -Get All rows from Rss Database, return arrays of SupabaseRss -*/ -func GetAllSupabaseRss() []SupabaseRss { - var result []SupabaseRss - err := pkg.SupabaseClient.DB.From(dbName).Select("*").Execute(&result) - if err != nil { - fmt.Println("Error calling GetAllSupabaseRss", err) - return nil - } - return result -} - -/* -Insert - -Insert a row into Rss Database -*/ -func Insert(feed *gofeed.Item) { - var results []gofeed.Feed - err := pkg.SupabaseClient.DB.From(dbName).Insert(SupabaseRss{ - Url: feed.Link, - Name: feed.Title, - Priority: 0, - Category: "", - }).Execute(&results) - if err != nil { - fmt.Println("Error calling Insert", err) - return - } -} - -/* -Delete - -Delete a row in Rss Database -*/ -func Delete(rss SupabaseRss) { - var results []SupabaseRss - err := pkg.SupabaseClient.DB.From(dbName).Delete().Eq("url", rss.Url).Execute(&results) - if err != nil { - fmt.Println("Error calling Delete", err) - return - } -} diff --git a/rss/telegram.go b/rss/telegram.go deleted file mode 100644 index 4833922..0000000 --- a/rss/telegram.go +++ /dev/null @@ -1,35 +0,0 @@ -package rss - -import ( - "github.com/mmcdole/gofeed" - "gobot/config" - tele "gopkg.in/telebot.v3" - "os" - "strconv" - "time" -) - -/* -SendRssItem - -Send Rss item url to config.TelegramRemoteOk channel -*/ -func SendRssItem(item gofeed.Item) { - pref := tele.Settings{ - Token: os.Getenv(config.TelegramBot), - Poller: &tele.LongPoller{Timeout: 10 * time.Second}, - } - - b, _ := tele.NewBot(pref) - - num, chatIdErr := strconv.ParseInt(os.Getenv(config.TelegramRss), 10, 64) - if chatIdErr != nil { - println("Error from send items chatIdErr", chatIdErr) - return - } - _, err := b.Send(tele.ChatID(num), item.Link) - if err != nil { - println("Error from send items", err) - return - } -}