Add follow and unfollow sub-commands

This commit is contained in:
Alessio 2022-02-26 16:22:00 -08:00
parent 857b9c5255
commit 41586bf0f8
3 changed files with 30 additions and 1 deletions

View File

@ -223,6 +223,14 @@ test -e profile_images/default_profile.png
tw fetch_user AlexKoppelman # This is probably kind of a flimsy test
test $(sqlite3 twitter.db "select is_content_downloaded from users where handle='AlexKoppelman'") = "1"
# Test following / unfollowing a user
test "$(sqlite3 twitter.db "select count(*) from users where is_followed = 1")" = "0"
tw follow michaelmalice
test "$(sqlite3 twitter.db "select handle from users where is_followed = 1")" = "michaelmalice"
tw unfollow michaelmalice
test "$(sqlite3 twitter.db "select count(*) from users where is_followed = 1")" = "0"
# TODO: Maybe this file should be broken up into multiple test scripts
echo -e "\033[32mAll tests passed. Finished successfully.\033[0m"

View File

@ -47,6 +47,10 @@ This application downloads tweets from twitter and saves them in a SQLite databa
Gets the most recent ~50 tweets.
If "get_user_tweets_all" is used, gets up to ~3200 tweets (API limit).
follow
unfollow
<TARGET> is the user handle
search
<TARGET> is the search query. Should be wrapped in quotes if it has spaces.

View File

@ -104,6 +104,10 @@ func main() {
download_tweet_content(target)
case "search":
search(target)
case "follow":
follow_user(target, true)
case "unfollow":
follow_user(target, false)
default:
die("Invalid operation: " + operation, true, 3)
}
@ -239,7 +243,6 @@ func download_user_content(handle scraper.UserHandle) {
}
}
func search(query string) {
trove, err := scraper.Search(query, 1000)
if err != nil {
@ -249,3 +252,17 @@ func search(query string) {
happy_exit(fmt.Sprintf("Saved %d tweets and %d users", len(trove.Tweets), len(trove.Users)))
}
func follow_user(handle string, is_followed bool) {
user, err := profile.GetUserByHandle(scraper.UserHandle(handle))
if err != nil {
panic("Couldn't get the user from database: " + err.Error())
}
profile.SetUserFollowed(&user, is_followed)
if is_followed {
happy_exit("Followed user: " + handle)
} else {
happy_exit("Unfollowed user: " + handle)
}
}