Add user search
This commit is contained in:
parent
00e92165f2
commit
c3d52348fc
@ -254,3 +254,22 @@ func (p Profile) get_profile_image_output_path(u scraper.User) string {
|
||||
}
|
||||
return path.Join(p.ProfileDir, "profile_images", u.ProfileImageLocalPath)
|
||||
}
|
||||
|
||||
// Do a text search for users
|
||||
func (p Profile) SearchUsers(s string) []scraper.User {
|
||||
var ret []scraper.User
|
||||
val := fmt.Sprintf("%%%s%%", s)
|
||||
err := p.DB.Select(&ret, `
|
||||
select id, display_name, handle, bio, following_count, followers_count, location, website, join_date, is_private, is_verified,
|
||||
is_banned, profile_image_url, profile_image_local_path, banner_image_url, banner_image_local_path, pinned_tweet_id,
|
||||
is_content_downloaded, is_followed
|
||||
from users
|
||||
where handle like ?
|
||||
or display_name like ?
|
||||
order by followers_count desc
|
||||
`, val, val)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
panic(err)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
@ -296,3 +296,15 @@ func TestCreateUnknownUserWithHandleThatAlreadyExists(t *testing.T) {
|
||||
assert.Equal(user.Bio, user_reloaded.Bio)
|
||||
assert.Equal(user.DisplayName, user_reloaded.DisplayName)
|
||||
}
|
||||
|
||||
func TestSearchUsers(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
profile_path := "../../sample_data/profile"
|
||||
profile := create_or_load_profile(profile_path)
|
||||
|
||||
users := profile.SearchUsers("no")
|
||||
assert.Len(users, 2)
|
||||
assert.Equal(users[0].Handle, scraper.UserHandle("Cernovich"))
|
||||
assert.Equal(users[1].Handle, scraper.UserHandle("CovfefeAnon"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user