diff --git a/cmd/tests.sh b/cmd/tests.sh index e06fc4c..586af06 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -235,7 +235,16 @@ test $(sqlite3 twitter.db "select is_content_downloaded from users where handle= 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 follow cernovich +test "$(tw list_followed | wc -l)" = 2 +test "$(tw list_followed | grep -iq cernovich && echo YES)" = "YES" +test "$(tw list_followed | grep -iq michaelmalice && echo YES)" = "YES" +test "$(tw list_followed | grep -iq blahblahgibberish && echo YES)" = "" + tw unfollow michaelmalice +test "$(sqlite3 twitter.db "select count(*) from users where is_followed = 1")" = "1" +tw unfollow cernovich 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 diff --git a/cmd/twitter/helpers.go b/cmd/twitter/helpers.go index 8f74b34..d1b879d 100644 --- a/cmd/twitter/helpers.go +++ b/cmd/twitter/helpers.go @@ -51,6 +51,10 @@ This application downloads tweets from twitter and saves them in a SQLite databa unfollow is the user handle + list_followed + No is needed; will be ignored if given. + Lists all the users (by their @handle) that are followed. + 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 0bc500d..9d1e64d 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -69,7 +69,12 @@ func main() { log.SetLevel(logging_level) if len(args) < 2 { - die("", true, 1) + if len(args) == 1 && args[0] == "list_followed" { + // "list_followed" doesn't need a target, so create a fake second arg + args = append(args, "") + } else { + die("", true, 1) + } } operation := args[0] @@ -108,6 +113,8 @@ func main() { follow_user(target, true) case "unfollow": follow_user(target, false) + case "list_followed": + list_followed() default: die("Invalid operation: " + operation, true, 3) } @@ -266,3 +273,9 @@ func follow_user(handle string, is_followed bool) { happy_exit("Unfollowed user: " + handle) } } + +func list_followed() { + for _, handle := range profile.GetAllFollowedUsers() { + fmt.Println(handle) + } +} diff --git a/persistence/user_queries.go b/persistence/user_queries.go index bd383ec..257645c 100644 --- a/persistence/user_queries.go +++ b/persistence/user_queries.go @@ -233,3 +233,24 @@ func (p Profile) NextFakeUserID() scraper.UserID { } return ret } + +func (p Profile) GetAllFollowedUsers() []scraper.UserHandle { + rows, err := p.DB.Query("select handle from users where is_followed = 1") + if err != nil { + panic(err) + } + + ret := []scraper.UserHandle{} + + var tmp scraper.UserHandle + + for rows.Next() { + err = rows.Scan(&tmp) + if err != nil { + panic(err) + } + ret = append(ret, tmp) + } + + return ret +} diff --git a/persistence/user_queries_test.go b/persistence/user_queries_test.go index de0d072..b7f0216 100644 --- a/persistence/user_queries_test.go +++ b/persistence/user_queries_test.go @@ -300,7 +300,6 @@ func TestCreateUnknownUserWithHandleThatAlreadyExists(t *testing.T) { user := create_stable_user() - unknown_user := scraper.GetUnknownUserWithHandle(user.Handle) assert.Equal(scraper.UserID(0), unknown_user.ID) diff --git a/scraper/api_request_utils.go b/scraper/api_request_utils.go index b5913b0..b49b976 100644 --- a/scraper/api_request_utils.go +++ b/scraper/api_request_utils.go @@ -332,7 +332,6 @@ func ApiRequestAddAllParams(req *http.Request) { query.Add("tweet_mode", "extended") query.Add("include_entities", "true") query.Add("include_user_entities", "true") - query.Add("include_ext_media_color", "true") query.Add("include_ext_media_availability", "true") query.Add("send_error_codes", "true") query.Add("simple_quoted_tweet", "true") diff --git a/scraper/user.go b/scraper/user.go index 84ef713..61a1284 100644 --- a/scraper/user.go +++ b/scraper/user.go @@ -102,6 +102,10 @@ func ParseHandleFromTweetUrl(tweet_url string) (UserHandle, error) { return UserHandle(matches[1]), nil } +/** + * Unknown Users with handles are only created by direct GetUser calls (either `twitter fetch_user` + * subcommand or as part of tombstone user fetching.) + */ func GetUnknownUserWithHandle(handle UserHandle) User { return User{ ID: UserID(0), // 2^62 + 1... @@ -114,7 +118,7 @@ func GetUnknownUserWithHandle(handle UserHandle) User { Website:"", JoinDate: time.Unix(0, 0), IsVerified: false, - IsPrivate: true, + IsPrivate: false, IsNeedingFakeID: true, IsIdFake: true, }