Add 'get_notifications' subcommand

This commit is contained in:
Alessio 2024-08-25 22:57:40 -07:00
parent b77612c66f
commit 04991ad554
2 changed files with 24 additions and 1 deletions

View File

@ -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"

View File

@ -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)
}