Add list_followed
subcommand
This commit is contained in:
parent
3c2aee5016
commit
508670248e
@ -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"
|
test "$(sqlite3 twitter.db "select count(*) from users where is_followed = 1")" = "0"
|
||||||
tw follow michaelmalice
|
tw follow michaelmalice
|
||||||
test "$(sqlite3 twitter.db "select handle from users where is_followed = 1")" = "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
|
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"
|
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
|
# TODO: Maybe this file should be broken up into multiple test scripts
|
||||||
|
@ -51,6 +51,10 @@ This application downloads tweets from twitter and saves them in a SQLite databa
|
|||||||
unfollow
|
unfollow
|
||||||
<TARGET> is the user handle
|
<TARGET> is the user handle
|
||||||
|
|
||||||
|
list_followed
|
||||||
|
No <TARGET> is needed; will be ignored if given.
|
||||||
|
Lists all the users (by their @handle) that are followed.
|
||||||
|
|
||||||
search
|
search
|
||||||
<TARGET> is the search query. Should be wrapped in quotes if it has spaces.
|
<TARGET> is the search query. Should be wrapped in quotes if it has spaces.
|
||||||
|
|
||||||
|
@ -69,8 +69,13 @@ func main() {
|
|||||||
log.SetLevel(logging_level)
|
log.SetLevel(logging_level)
|
||||||
|
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
|
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)
|
die("", true, 1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
operation := args[0]
|
operation := args[0]
|
||||||
target := args[1]
|
target := args[1]
|
||||||
@ -108,6 +113,8 @@ func main() {
|
|||||||
follow_user(target, true)
|
follow_user(target, true)
|
||||||
case "unfollow":
|
case "unfollow":
|
||||||
follow_user(target, false)
|
follow_user(target, false)
|
||||||
|
case "list_followed":
|
||||||
|
list_followed()
|
||||||
default:
|
default:
|
||||||
die("Invalid operation: " + operation, true, 3)
|
die("Invalid operation: " + operation, true, 3)
|
||||||
}
|
}
|
||||||
@ -266,3 +273,9 @@ func follow_user(handle string, is_followed bool) {
|
|||||||
happy_exit("Unfollowed user: " + handle)
|
happy_exit("Unfollowed user: " + handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func list_followed() {
|
||||||
|
for _, handle := range profile.GetAllFollowedUsers() {
|
||||||
|
fmt.Println(handle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -233,3 +233,24 @@ func (p Profile) NextFakeUserID() scraper.UserID {
|
|||||||
}
|
}
|
||||||
return ret
|
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
|
||||||
|
}
|
||||||
|
@ -300,7 +300,6 @@ func TestCreateUnknownUserWithHandleThatAlreadyExists(t *testing.T) {
|
|||||||
|
|
||||||
user := create_stable_user()
|
user := create_stable_user()
|
||||||
|
|
||||||
|
|
||||||
unknown_user := scraper.GetUnknownUserWithHandle(user.Handle)
|
unknown_user := scraper.GetUnknownUserWithHandle(user.Handle)
|
||||||
assert.Equal(scraper.UserID(0), unknown_user.ID)
|
assert.Equal(scraper.UserID(0), unknown_user.ID)
|
||||||
|
|
||||||
|
@ -332,7 +332,6 @@ func ApiRequestAddAllParams(req *http.Request) {
|
|||||||
query.Add("tweet_mode", "extended")
|
query.Add("tweet_mode", "extended")
|
||||||
query.Add("include_entities", "true")
|
query.Add("include_entities", "true")
|
||||||
query.Add("include_user_entities", "true")
|
query.Add("include_user_entities", "true")
|
||||||
query.Add("include_ext_media_color", "true")
|
|
||||||
query.Add("include_ext_media_availability", "true")
|
query.Add("include_ext_media_availability", "true")
|
||||||
query.Add("send_error_codes", "true")
|
query.Add("send_error_codes", "true")
|
||||||
query.Add("simple_quoted_tweet", "true")
|
query.Add("simple_quoted_tweet", "true")
|
||||||
|
@ -102,6 +102,10 @@ func ParseHandleFromTweetUrl(tweet_url string) (UserHandle, error) {
|
|||||||
return UserHandle(matches[1]), nil
|
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 {
|
func GetUnknownUserWithHandle(handle UserHandle) User {
|
||||||
return User{
|
return User{
|
||||||
ID: UserID(0), // 2^62 + 1...
|
ID: UserID(0), // 2^62 + 1...
|
||||||
@ -114,7 +118,7 @@ func GetUnknownUserWithHandle(handle UserHandle) User {
|
|||||||
Website:"<blank>",
|
Website:"<blank>",
|
||||||
JoinDate: time.Unix(0, 0),
|
JoinDate: time.Unix(0, 0),
|
||||||
IsVerified: false,
|
IsVerified: false,
|
||||||
IsPrivate: true,
|
IsPrivate: false,
|
||||||
IsNeedingFakeID: true,
|
IsNeedingFakeID: true,
|
||||||
IsIdFake: true,
|
IsIdFake: true,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user