From 04991ad55472c835ea21b65a15599b64b3b4f3fd Mon Sep 17 00:00:00 2001 From: Alessio Date: Sun, 25 Aug 2024 22:57:40 -0700 Subject: [PATCH] Add 'get_notifications' subcommand --- cmd/tests.sh | 5 +++++ cmd/twitter/main.go | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/tests.sh b/cmd/tests.sh index 5a0342b..3fa295f 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -390,6 +390,11 @@ tw get_bookmarks test $(sqlite3 twitter.db "select count(*) from bookmarks") -ge "2" test $(sqlite3 twitter.db "select count(*) from bookmarks where tweet_id = 1762239926437843421") = "1" +# Test fetching notifications +tw get_notifications +test $(sqlite3 twitter.db "select count(*) from notifications") -ge "5" + + # Test fetch inbox test $(sqlite3 twitter.db "select count(*) from chat_rooms") = "0" test $(sqlite3 twitter.db "select count(*) from chat_messages") = "0" diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index 77bec81..5b8210c 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -82,7 +82,8 @@ func main() { if len(args) < 2 { if len(args) == 1 && (args[0] == "list_followed" || args[0] == "webserver" || args[0] == "fetch_timeline" || - args[0] == "fetch_timeline_following_only" || args[0] == "fetch_inbox" || args[0] == "get_bookmarks") { + args[0] == "fetch_timeline_following_only" || args[0] == "fetch_inbox" || args[0] == "get_bookmarks" || + args[0] == "get_notifications") { // Doesn't need a target, so create a fake second arg args = append(args, "") } else { @@ -186,6 +187,8 @@ func main() { fetch_timeline(false) // TODO: *how_many case "fetch_timeline_following_only": fetch_timeline(true) + case "get_notifications": + get_notifications(*how_many) case "download_tweet_content": download_tweet_content(target) case "search": @@ -594,3 +597,18 @@ func send_dm_reacc(room_id string, in_reply_to_id int, reacc string) { happy_exit("Sent the reaction", nil) } + +func get_notifications(how_many int) { + resp, err := api.GetNotifications("") // TODO: how_many + if err != nil { + panic(err) + } + trove, err := resp.ToTweetTroveAsNotifications(api.UserID) + if err != nil { + panic(err) + } + profile.SaveTweetTrove(trove, true, &api) + happy_exit(fmt.Sprintf("Saved %d notifications, %d tweets and %d users", + len(trove.Notifications), len(trove.Tweets), len(trove.Users), + ), nil) +}