diff --git a/cmd/tests.sh b/cmd/tests.sh index 146747d..3352c5e 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -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" diff --git a/cmd/twitter/helpers.go b/cmd/twitter/helpers.go index 7b5749c..8f74b34 100644 --- a/cmd/twitter/helpers.go +++ b/cmd/twitter/helpers.go @@ -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 + is the user handle + search is the search query. Should be wrapped in quotes if it has spaces. diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index b15ddc6..b107679 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -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) + } +}