Remove some useless functions ('list_followed', superceded by Lists; 'UserExists')
This commit is contained in:
parent
4ea15f10af
commit
51eaa2a0c4
@ -75,10 +75,6 @@ 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.
|
||||||
(Requires authentication)
|
(Requires authentication)
|
||||||
|
@ -81,7 +81,7 @@ 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" || args[0] == "webserver" || args[0] == "fetch_timeline" ||
|
if len(args) == 1 && (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") {
|
args[0] == "get_notifications") {
|
||||||
// Doesn't need a target, so create a fake second arg
|
// Doesn't need a target, so create a fake second arg
|
||||||
@ -203,8 +203,6 @@ 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()
|
|
||||||
case "like_tweet":
|
case "like_tweet":
|
||||||
like_tweet(target)
|
like_tweet(target)
|
||||||
case "unlike_tweet":
|
case "unlike_tweet":
|
||||||
@ -558,12 +556,6 @@ func like_tweet(tweet_identifier string) {
|
|||||||
happy_exit("Liked the tweet.", nil)
|
happy_exit("Liked the tweet.", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func list_followed() {
|
|
||||||
for _, handle := range profile.GetAllFollowedUsers() {
|
|
||||||
fmt.Println(handle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func start_webserver(addr string, should_auto_open bool) {
|
func start_webserver(addr string, should_auto_open bool) {
|
||||||
app := webserver.NewApp(profile)
|
app := webserver.NewApp(profile)
|
||||||
if api.UserHandle != "" {
|
if api.UserHandle != "" {
|
||||||
|
@ -73,28 +73,6 @@ func (p Profile) SaveUser(u *scraper.User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the database has a User with the given user handle.
|
|
||||||
//
|
|
||||||
// args:
|
|
||||||
// - handle: the user handle to search for
|
|
||||||
//
|
|
||||||
// returns:
|
|
||||||
// - true if there is such a User in the database, false otherwise
|
|
||||||
func (p Profile) UserExists(handle scraper.UserHandle) bool {
|
|
||||||
db := p.DB
|
|
||||||
|
|
||||||
var dummy string
|
|
||||||
err := db.QueryRow("select 1 from users where lower(handle) = lower(?)", handle).Scan(&dummy)
|
|
||||||
if err != nil {
|
|
||||||
if !errors.Is(err, sql.ErrNoRows) {
|
|
||||||
// A real error
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve a User from the database, by handle.
|
// Retrieve a User from the database, by handle.
|
||||||
//
|
//
|
||||||
// args:
|
// args:
|
||||||
@ -212,28 +190,8 @@ func (p Profile) NextFakeUserID() scraper.UserID {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Profile) GetAllFollowedUsers() []scraper.UserHandle {
|
// TODO: This is only used in checking whether the media downloader should get the big or small version of
|
||||||
rows, err := p.DB.Query("select handle from users where is_followed = 1")
|
// a profile image. That should be rewritten
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Profile) IsFollowing(user scraper.User) bool {
|
func (p Profile) IsFollowing(user scraper.User) bool {
|
||||||
row := p.DB.QueryRow("select is_followed from users where id like ?", user.ID)
|
row := p.DB.QueryRow("select is_followed from users where id like ?", user.ID)
|
||||||
var ret bool
|
var ret bool
|
||||||
|
@ -112,24 +112,6 @@ func TestHandleIsCaseInsensitive(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should correctly report whether the user exists in the database
|
|
||||||
func TestUserExists(t *testing.T) {
|
|
||||||
require := require.New(t)
|
|
||||||
profile_path := "test_profiles/TestUserQueries"
|
|
||||||
profile := create_or_load_profile(profile_path)
|
|
||||||
|
|
||||||
user := create_dummy_user()
|
|
||||||
|
|
||||||
exists := profile.UserExists(user.Handle)
|
|
||||||
require.False(exists)
|
|
||||||
|
|
||||||
err := profile.SaveUser(&user)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
exists = profile.UserExists(user.Handle)
|
|
||||||
require.True(exists)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test scenarios relating to user content downloading
|
// Test scenarios relating to user content downloading
|
||||||
func TestCheckUserContentDownloadNeeded(t *testing.T) {
|
func TestCheckUserContentDownloadNeeded(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user