From 56870173e92e78d7eef53b5f45353288d974fcf5 Mon Sep 17 00:00:00 2001 From: Alessio Date: Tue, 18 Jan 2022 17:48:08 -0800 Subject: [PATCH] Fix bug with users with 600x200 banner images When downloading these users' content, they weren't getting saved afterward (to update 'is_content_downloaded'). --- cmd/tests.sh | 13 +++++++++---- persistence/media_download.go | 8 ++++---- persistence/tweet_queries_test.go | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/tests.sh b/cmd/tests.sh index 4f921d2..c658a7a 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -194,10 +194,10 @@ test $(find link_preview_images | wc -l) = $initial_link_preview_images_count # # Test a tweet thread with tombstones -# tw fetch_tweet https://twitter.com/CovfefeAnon/status/1454526270809726977 # TODO: This guy un-privated for some reason -# test $(sqlite3 twitter.db "select is_stub from tweets where id = 1454515503242829830") = 1 -# test $(sqlite3 twitter.db "select is_stub from tweets where id = 1454521424144654344") = 0 -# test $(sqlite3 twitter.db "select is_stub from tweets where id = 1454522147750260742") = 1 +tw fetch_tweet https://twitter.com/CovfefeAnon/status/1454526270809726977 +test $(sqlite3 twitter.db "select is_stub from tweets where id = 1454515503242829830") = 1 +test $(sqlite3 twitter.db "select is_stub from tweets where id = 1454521424144654344") = 0 +test $(sqlite3 twitter.db "select is_stub from tweets where id = 1454522147750260742") = 1 # Test search tw search "from:michaelmalice constitution" @@ -215,6 +215,11 @@ 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 + +# Fetch a user with "600x200" banner image +tw fetch_user AlexKoppelman # This is probably kind of a flimsy test +test $(sqlite3 twitter.db "select is_content_downloaded from users where handle='AlexKoppelman'") = "1" + # TODO: Maybe this file should be broken up into multiple test scripts echo -e "\033[32mAll tests passed. Finished successfully.\033[0m" diff --git a/persistence/media_download.go b/persistence/media_download.go index 40bf1ac..38881cb 100644 --- a/persistence/media_download.go +++ b/persistence/media_download.go @@ -167,11 +167,11 @@ func (p Profile) DownloadUserContentWithInjector(u *scraper.User, downloader Med if u.BannerImageLocalPath != "" { outfile = path.Join(p.ProfileDir, "profile_images", u.BannerImageLocalPath) err = downloader.Curl(u.BannerImageUrl, outfile) + if err != nil && strings.Contains(err.Error(), "404 Not Found") { + // Try adding "600x200". Not sure why this does this but sometimes it does. + err = downloader.Curl(u.BannerImageUrl + "/600x200", outfile) + } if err != nil { - if strings.Contains(err.Error(), "404 Not Found") { - // Try adding "600x200". Not sure why this does this but sometimes it does. - err = downloader.Curl(u.BannerImageUrl + "/600x200", outfile) - } return err } } diff --git a/persistence/tweet_queries_test.go b/persistence/tweet_queries_test.go index cc355b8..6e83801 100644 --- a/persistence/tweet_queries_test.go +++ b/persistence/tweet_queries_test.go @@ -161,7 +161,7 @@ func TestModifyTweet(t *testing.T) { t.Errorf("Expected %d retweets, got %d", 2500, new_tweet.NumRetweets) } if new_tweet.NumReplies != 3500 { - t.Errorf("Expected %d replies, got %d", 1500, new_tweet.NumReplies) + t.Errorf("Expected %d replies, got %d", 3500, new_tweet.NumReplies) } if new_tweet.NumQuoteTweets != 4500 { t.Errorf("Expected %d quote tweets, got %d", 4500, new_tweet.NumQuoteTweets)