From e71e32228c2693aa8f09882632bf7053aa6f10b6 Mon Sep 17 00:00:00 2001 From: Alessio Date: Fri, 7 Jan 2022 17:33:26 -0500 Subject: [PATCH] Get rid of tiny default profile images (default image is small enough, doesn't need a tiny version) --- cmd/tests.sh | 6 +++--- scraper/user.go | 5 ++--- scraper/user_test.go | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/tests.sh b/cmd/tests.sh index 522648a..4f921d2 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -97,14 +97,14 @@ test $(find videos | wc -l) = "$((initial_videos_count + 1))" # Download a full thread -test ! -e profile_images/default_profile_normal.png +test ! -e profile_images/default_profile.png tw fetch_tweet https://twitter.com/RememberAfghan1/status/1429585423702052867 test $(sqlite3 twitter.db "select handle from tweets join users on tweets.user_id = users.id where tweets.id=1429585423702052867") = "RememberAfghan1" test $(sqlite3 twitter.db "select is_conversation_scraped, abs(last_scraped_at - strftime('%s','now')) < 30 from tweets where id = 1429585423702052867") = "1|1" test $(sqlite3 twitter.db "select handle from tweets join users on tweets.user_id = users.id where tweets.id=1429584239570391042") = "michaelmalice" test $(sqlite3 twitter.db "select is_conversation_scraped from tweets where id = 1429584239570391042") = "0" test "$(sqlite3 twitter.db "select handle, is_banned from tweets join users on tweets.user_id = users.id where tweets.id=1429583672827465730")" = "kanesays23|1" # This guy got banned -test -e profile_images/default_profile_normal.png +test -e profile_images/default_profile.png test $(sqlite3 twitter.db "select handle from tweets join users on tweets.user_id = users.id where tweets.id=1429616911315345414") = "NovaValentis" test $(sqlite3 twitter.db "select reply_mentions from tweets where id = 1429585423702052867") = "michaelmalice" test $(sqlite3 twitter.db "select reply_mentions from tweets where id = 1429616911315345414") = "RememberAfghan1,michaelmalice" @@ -210,7 +210,7 @@ test "$(sqlite3 twitter.db "select choice1_votes, choice2_votes, choice3_votes, # Test fetching a banned user -test ! -e profile_images/default_profile.png +rm profile_images/default_profile.png tw fetch_user nancytracker test "$(sqlite3 twitter.db "select is_content_downloaded, is_banned from users where handle='nancytracker'")" = "1|1" test -e profile_images/default_profile.png diff --git a/scraper/user.go b/scraper/user.go index 0eae868..1d1b225 100644 --- a/scraper/user.go +++ b/scraper/user.go @@ -178,14 +178,13 @@ func (u User) compute_banner_image_local_path() string { * Get the URL where we would expect to find a User's tiny profile image */ func (u User) GetTinyProfileImageUrl() string { - r := regexp.MustCompile(`(\.\w{2,4})$`) - // If profile image is empty, then just use the default profile image if u.ProfileImageUrl == "" { - return r.ReplaceAllString(DEFAULT_PROFILE_IMAGE_URL, "_normal$1") + return DEFAULT_PROFILE_IMAGE_URL } // Check that the format is as expected + r := regexp.MustCompile(`(\.\w{2,4})$`) if !r.MatchString(u.ProfileImageUrl) { panic(fmt.Sprintf("Weird profile image url: %s", u.ProfileImageUrl)) } diff --git a/scraper/user_test.go b/scraper/user_test.go index e86172a..54a56e9 100644 --- a/scraper/user_test.go +++ b/scraper/user_test.go @@ -117,10 +117,10 @@ func TestParseBannedUser(t *testing.T) { } // Test generation of profile images for banned user - if user.GetTinyProfileImageUrl() != "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png" { + if user.GetTinyProfileImageUrl() != "https://abs.twimg.com/sticky/default_profile_images/default_profile.png" { t.Errorf("Incorrect tiny profile image URL for banned user: %q", user.GetTinyProfileImageUrl()) } - if user.GetTinyProfileImageLocalPath() != "default_profile_normal.png" { + if user.GetTinyProfileImageLocalPath() != "default_profile.png" { t.Errorf("Incorrect tiny profile image local path for banned user: %q", user.GetTinyProfileImageLocalPath()) } }