2021-08-02 14:46:06 -07:00
#!/bin/bash
set -e
set -x
2021-08-03 17:34:44 -07:00
PS4 = '+(${BASH_SOURCE}:${LINENO}): '
2024-08-19 14:15:57 -07:00
if [ [ -z " $OFFLINE_TWATTER_PASSWD " && -z " $SESSION_FILE_PATH " ] ] ; then
echo "Neither SESSION_FILE_PATH nor OFFLINE_TWATTER_PASSWD is set! Please provide one or the other. Exiting."
2023-03-09 22:55:02 -05:00
exit 1
fi
2024-08-19 14:15:57 -07:00
2022-01-04 12:57:43 -05:00
FAKE_VERSION = "1.100.3489"
./compile.sh $FAKE_VERSION
2021-08-07 17:06:39 -07:00
2024-09-15 15:18:54 -07:00
test -e data/profile && rm -r data/profile
2021-08-02 14:46:06 -07:00
2021-08-11 06:56:42 -07:00
PATH = ` pwd ` :$PATH
2022-01-04 12:57:43 -05:00
test " $( tw --version) " = " v $FAKE_VERSION "
2022-02-12 15:41:03 -08:00
tw --help
test $? -eq 0
2024-09-15 15:22:07 -07:00
mkdir -p data
2024-09-15 15:18:54 -07:00
tw create_profile data/profile
cd data/profile
2021-08-11 06:56:42 -07:00
2024-03-02 15:56:52 -08:00
# Should only contain default profile image
test $( find profile_images | wc -l) = "2"
test -f profile_images/default_profile.png
2023-06-21 13:10:59 -03:00
# Print an error message in red before exiting if a test fails
trap 'echo -e "\033[31mTEST FAILURE. Aborting\033[0m"' ERR
2024-08-19 14:15:57 -07:00
# If a SESSION_FILE_PATH is provided, then use it instead of logging in
if [ [ -n " $SESSION_FILE_PATH " ] ] ; then
echo " Using provided session file: $SESSION_FILE_PATH "
2024-08-23 13:24:11 -07:00
wc -c $SESSION_FILE_PATH
2024-08-19 14:15:57 -07:00
cp $SESSION_FILE_PATH Offline_Twatter.session
else
# Testing login
test ! -e Offline_Twatter.session
tw login offline_twatter " $OFFLINE_TWATTER_PASSWD "
fi
# Ensure session file is valid
2024-08-23 13:24:11 -07:00
test -f Offline_Twatter.session
2023-08-22 20:12:50 -03:00
test " $( jq .UserHandle Offline_Twatter.session) " = "\"Offline_Twatter\""
test " $( jq .IsAuthenticated Offline_Twatter.session) " = "true"
jq .CSRFToken Offline_Twatter.session | grep -P '"\w+"'
2024-08-19 14:15:57 -07:00
2023-08-22 20:12:50 -03:00
shopt -s expand_aliases
alias tw = "tw --session Offline_Twatter"
2023-06-21 13:10:59 -03:00
2024-08-19 14:15:57 -07:00
2021-08-02 14:46:06 -07:00
# Fetch a user
2024-03-02 15:56:52 -08:00
initial_profile_images_count = $( find profile_images | wc -l)
2022-03-13 14:46:44 -07:00
tw fetch_user wrathofgnon
test " $( sqlite3 twitter.db "select handle from users" ) " = "wrathofgnon"
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from users" ) = "1"
2022-03-13 14:46:44 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle = 'wrathofgnon'" ) = "1"
2024-03-02 15:56:52 -08:00
test $( find profile_images | wc -l) = " $(( $initial_profile_images_count + 2 )) " # should have gotten 2 images
2022-03-13 14:46:44 -07:00
test -f profile_images/wrathofgnon_profile_fB-3BRin.jpg
test -f profile_images/wrathofgnon_banner_1503908468.jpg
tw fetch_user wrathofgnon # try to double-download it
2021-09-27 12:54:18 -07:00
test $( sqlite3 twitter.db "select count(*) from users" ) = "1" # shouldn't have added a new row
2021-08-02 14:46:06 -07:00
2021-08-22 17:55:21 -07:00
2022-03-13 14:46:44 -07:00
# # Fetch a tweet with images
tw fetch_tweet_only https://twitter.com/wrathofgnon/status/1503016316642689026
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from tweets" ) = "1"
2022-03-13 14:46:44 -07:00
test " $( sqlite3 twitter.db "select text from tweets" ) " = "The I Am A Mayor Who Is Serious About Reducing My Town's Dependence on Fossil Fuels Starter Pack. Inquire within for more details."
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from images" ) = "4"
2021-08-07 17:06:39 -07:00
# Download its images
2022-03-13 14:46:44 -07:00
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1503016316642689026 and is_downloaded = 0" ) = "4"
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1503016316642689026 and is_downloaded = 1" ) = "0"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1503016316642689026" ) = "0"
2022-10-15 15:06:06 -04:00
test $( find images -mindepth 2 | wc -l) = "0"
2022-03-13 14:46:44 -07:00
tw download_tweet_content https://twitter.com/wrathofgnon/status/1503016316642689026
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1503016316642689026 and is_downloaded = 0" ) = "0"
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1503016316642689026 and is_downloaded = 1" ) = "4"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1503016316642689026" ) = "1"
2022-10-15 15:06:06 -04:00
test $( find images -mindepth 2 | wc -l) = "4"
2021-08-05 14:10:46 -07:00
# Try to double-download it
2022-03-13 14:46:44 -07:00
tw fetch_tweet_only https://twitter.com/wrathofgnon/status/1503016316642689026
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from tweets" ) = "1"
test $( sqlite3 twitter.db "select count(*) from images" ) = "4"
2021-08-05 14:10:46 -07:00
# Fetch a tweet with a video
2022-10-14 22:44:02 -04:00
tw fetch_user SpaceX
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select handle from users" | wc -l) = "2"
2022-10-14 22:44:02 -04:00
tw fetch_tweet_only https://twitter.com/SpaceX/status/1581025285524242432
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from tweets" ) = "2"
test $( sqlite3 twitter.db "select count(*) from videos" ) = "1"
2021-08-07 17:06:39 -07:00
# Download the video
2022-10-14 22:44:02 -04:00
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1581025285524242432 and is_downloaded = 0" ) = "1"
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1581025285524242432 and is_downloaded = 1" ) = "0"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1581025285524242432" ) = "0"
2022-10-15 15:06:06 -04:00
test $( find videos -mindepth 2 | wc -l) = "0"
test $( find video_thumbnails -mindepth 2| wc -l) = "0"
2022-10-14 22:44:02 -04:00
tw download_tweet_content 1581025285524242432
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1581025285524242432 and is_downloaded = 0" ) = "0"
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1581025285524242432 and is_downloaded = 1" ) = "1"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1581025285524242432" ) = "1"
2022-10-15 15:06:06 -04:00
test $( find videos -mindepth 2 | wc -l) = "1"
test $( find video_thumbnails -mindepth 2 | wc -l) = "1"
2021-08-05 14:10:46 -07:00
# Try to double-download it
2022-10-14 22:44:02 -04:00
tw fetch_tweet_only https://twitter.com/SpaceX/status/1581025285524242432
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from tweets" ) = "2"
test $( sqlite3 twitter.db "select count(*) from videos" ) = "1"
2021-08-05 14:10:46 -07:00
2021-08-07 17:06:39 -07:00
2021-10-04 21:06:53 -07:00
# Fetch a tweet with a GIF
tw fetch_user Cernovich
2022-10-15 15:06:06 -04:00
initial_videos_count = $( find videos -mindepth 2 | wc -l) # Don't count prefix dirs
2021-10-04 21:06:53 -07:00
initial_videos_db_count = $( sqlite3 twitter.db "select count(*) from videos" )
tw fetch_tweet_only https://twitter.com/Cernovich/status/1444429517020274693
test $( sqlite3 twitter.db "select count(*) from videos" ) = " $(( initial_videos_db_count + 1 )) "
test $( sqlite3 twitter.db "select is_gif from videos where tweet_id = 1444429517020274693" ) = "1"
# Download the GIF
2022-10-15 15:06:06 -04:00
test $( find videos -mindepth 2 | wc -l) = " $(( initial_videos_count)) " # Shouldn't have changed yet
2021-10-04 21:06:53 -07:00
tw download_tweet_content https://twitter.com/Cernovich/status/1444429517020274693
2022-10-15 15:06:06 -04:00
test $( find videos -mindepth 2 | wc -l) = " $(( initial_videos_count + 1 )) "
2021-10-04 21:06:53 -07:00
2022-10-15 15:50:25 -04:00
# Fetch a tweet with 2 gifs
initial_videos_count = $( find videos -mindepth 2 | wc -l)
2023-02-05 23:33:36 -05:00
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1582197943511023616 and is_gif = 1" ) = "0"
tw fetch_tweet 1582197943511023616
2022-10-15 15:50:25 -04:00
test $( find videos -mindepth 2 | wc -l) = " $(( initial_videos_count + 2 )) "
2023-02-05 23:33:36 -05:00
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1582197943511023616 and is_gif = 1" ) = "2"
2022-10-15 15:50:25 -04:00
# Fetch a tweet with 2 videos
2022-11-13 11:29:47 -05:00
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1591025378143129601 and is_gif = 0" ) = "0"
tw fetch_user alifarhat79
tw fetch_tweet_only https://twitter.com/alifarhat79/status/1591025378143129601
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1591025378143129601 and is_gif = 0" ) = "2"
2022-10-15 15:50:25 -04:00
initial_videos_count = $( find videos -mindepth 2 | wc -l)
2022-11-13 11:29:47 -05:00
tw download_tweet_content https://twitter.com/alifarhat79/status/1591025378143129601
2022-10-15 15:50:25 -04:00
test $( find videos -mindepth 2 | wc -l) = " $(( initial_videos_count + 2 )) "
# Fetch a tweet with a video and an image
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1579292281898766336" ) = "0"
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1579292281898766336" ) = "0"
tw fetch_user mexicanwilddog
tw fetch_tweet_only https://twitter.com/mexicanwilddog/status/1579292281898766336
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1579292281898766336" ) = "1"
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1579292281898766336" ) = "1"
initial_videos_count = $( find videos -mindepth 2 | wc -l)
initial_images_count = $( find images -mindepth 2 | wc -l)
tw download_tweet_content https://twitter.com/mexicanwilddog/status/1579292281898766336
test $( find videos -mindepth 2 | wc -l) = " $(( initial_videos_count + 1 )) "
test $( find images -mindepth 2 | wc -l) = " $(( initial_images_count + 1 )) "
2022-12-03 13:47:34 -05:00
# Fetch and attempt to download a DMCAed tweet
2024-12-09 11:52:17 -08:00
tw fetch_user TyCardon
tw fetch_tweet_only https://twitter.com/TyCardon/status/1480640777281839106
tw download_tweet_content 1480640777281839106
test $( sqlite3 twitter.db "select is_blocked_by_dmca, is_downloaded from videos where tweet_id = 1480640777281839106" ) = "1|0"
2022-10-15 15:50:25 -04:00
2022-05-14 17:00:56 -07:00
# Fetch a tweet with a poll
tw fetch_tweet 1465534109573390348
test $( sqlite3 twitter.db "select count(*) from polls where tweet_id = 1465534109573390348" ) = "1"
test " $( sqlite3 twitter.db "select choice1, choice2, choice3, choice4 from polls where tweet_id = 1465534109573390348" ) " = "Tribal armband|Marijuana leaf|Butterfly|Maple leaf"
test " $( sqlite3 twitter.db "select choice1_votes, choice2_votes, choice3_votes, choice4_votes from polls where tweet_id = 1465534109573390348" ) " = "1593|624|778|1138"
# Fetch a tweet with a Twitter Space
2024-06-10 17:14:44 -07:00
tw fetch_tweet https://x.com/AGAndrewBailey/status/1769857889802359212
2022-05-14 17:00:56 -07:00
test $( sqlite3 twitter.db "select count(*) from spaces" ) = "1"
2024-06-10 17:14:44 -07:00
test $( sqlite3 twitter.db "select space_id from tweets where id = 1769857889802359212" ) = "1BRJjPVmBBRKw"
2021-10-04 21:06:53 -07:00
2021-08-22 17:55:21 -07:00
# Download a full thread
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"
2024-02-18 13:43:31 -08:00
test $( sqlite3 twitter.db "select is_conversation_scraped, abs(last_scraped_at - strftime('%s','now') || substr(strftime('%f','now'),4)) < 30000 from tweets where id = 1429585423702052867" ) = "1|1"
2021-08-22 17:55:21 -07:00
test $( sqlite3 twitter.db "select handle from tweets join users on tweets.user_id = users.id where tweets.id=1429584239570391042" ) = "michaelmalice"
2021-12-20 15:27:59 -05:00
test $( sqlite3 twitter.db "select is_conversation_scraped from tweets where id = 1429584239570391042" ) = "0"
2022-01-07 13:42:00 -05:00
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
2021-09-17 17:35:55 -07:00
test $( sqlite3 twitter.db "select handle from tweets join users on tweets.user_id = users.id where tweets.id=1429616911315345414" ) = "NovaValentis"
2021-09-27 18:29:55 -07:00
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"
2021-08-22 17:55:21 -07:00
2022-01-05 12:37:11 -05:00
# Test that profile images (tiny vs regular) are chosen properly
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle = 'Cernovich'" ) = "1"
test $( find profile_images/Cernovich* | grep normal | wc -l) = "0" # Since "Cernovich" was fetched directly, should have full-sized profile image and banner
test $( find profile_images/Cernovich* | grep banner | wc -l) = "1"
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle = 'RememberAfghan1'" ) = "0"
test $( find profile_images/RememberAfghan1* | grep normal | wc -l) = "1" # "RememberAfghan1" was fetched via a tweet thread and isn't followed, so should have tiny profile image and no banner
test $( find profile_images/RememberAfghan1* | grep banner | wc -l) = "0"
2021-08-11 06:56:42 -07:00
# Test that the `--profile` flag works
2024-09-15 15:18:54 -07:00
cd ../..
tw --profile data/profile fetch_user elonmusk
test $( sqlite3 data/profile/twitter.db "select count(*) from users where handle = 'elonmusk'" ) = "1"
cd -
2021-08-19 12:54:08 -07:00
2021-09-27 13:49:17 -07:00
# Test that fetching tweets with ID only (not full URL) works
test $( sqlite3 twitter.db "select count(*) from tweets where id = 1433713164546293767" ) = "0" # Check it's not already there
2021-10-09 18:58:52 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle='elonmusk'" ) = "1" # Should be downloaded from the previous test!
2021-09-27 13:49:17 -07:00
tw fetch_tweet 1433713164546293767
test $( sqlite3 twitter.db "select count(*) from tweets where id = 1433713164546293767" ) = "1" # Should be there now
2021-10-09 18:58:52 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle='elonmusk'" ) = "1" # Should not un-set content-downloaded!
2021-09-27 13:49:17 -07:00
2021-08-19 12:54:08 -07:00
# Get a user's feed
2024-12-22 08:04:18 -08:00
tw fetch_user cernovich
cernovich_id = $( sqlite3 twitter.db "select id from users where handle like 'cernovich'" )
2021-08-19 12:54:08 -07:00
test $( sqlite3 twitter.db "select count(*) from retweets" ) = "0"
tweet_count_1 = $( sqlite3 twitter.db "select count(*) from tweets" )
2024-12-22 08:04:18 -08:00
tw get_user_tweets cernovich
2021-08-19 12:54:08 -07:00
# Check that there are some retweets
rts_count = $( sqlite3 twitter.db "select count(*) from retweets" )
2024-03-12 09:25:51 -07:00
test $rts_count -gt "0"
2021-08-19 12:54:08 -07:00
# Check that new retweets plus new tweets > 50
tweet_count_2 = $( sqlite3 twitter.db "select count(*) from tweets" )
2024-12-22 08:04:18 -08:00
test $( sqlite3 twitter.db " select count(*) from retweets where retweeted_by != $cernovich_id " ) = "0"
2021-08-19 12:54:08 -07:00
test $(( $rts_count + $tweet_count_2 - $tweet_count_1 )) -gt "50"
2021-08-10 22:06:03 -07:00
2021-08-22 16:41:59 -07:00
# Fetch a privated user
2022-01-30 15:16:04 -08:00
tw fetch_user LandsharkRides
test $( sqlite3 twitter.db "select is_private from users where handle = 'LandsharkRides'" ) = "1"
2021-08-22 16:41:59 -07:00
2024-09-22 22:58:32 -07:00
2024-12-09 12:59:46 -08:00
# # Fetch a user who deleted and made a new account with the same handle
# TODO: this guy got banned
# sqlite3 twitter.db "INSERT INTO users(rowid,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,is_id_fake,is_deleted) VALUES(134934,1615394007961731072,'Monsieur Chat ✊🏼','9MonsieurChat9','Lives: 4 (-5)',121,694,'','',1673974925000,0,0,0,'https://pbs.twimg.com/profile_images/1818708927842074627/O0i9kUeI.jpg','9MonsieurChat9_profile_O0i9kUeI.jpg','','',1834121200584589600,0,0,0,0)"
# test $(sqlite3 twitter.db "select count(*) from users where handle like '9MonsieurChat9'") = "1"
# tw fetch_user 9MonsieurChat9 # Should get the updated one
# test $(sqlite3 twitter.db "select count(*) from users where handle like '9MonsieurChat9'") = "2"
# test $(sqlite3 twitter.db "select count(*) from users where handle like '9MonsieurChat9' and not is_deleted") = "1"
# test $(sqlite3 twitter.db "select is_deleted from users where id = 1615394007961731072") = "1"
2024-12-09 13:08:48 -08:00
#
# # Fetch a tweet from such a new account with the same handle as an old one
# sqlite3 twitter.db "delete from users where handle like '9MonsieurChat9' and not is_deleted"
# test $(sqlite3 twitter.db "select count(*) from users where handle like '9MonsieurChat9'") = "1"
# tw fetch_tweet https://x.com/9MonsieurChat9/status/1834121200584589600 # Should update the user as well
# test $(sqlite3 twitter.db "select count(*) from users where handle like '9MonsieurChat9'") = "2"
# test $(sqlite3 twitter.db "select count(*) from users where handle like '9MonsieurChat9' and not is_deleted") = "1"
# test $(sqlite3 twitter.db "select is_deleted from users where id = 1615394007961731072") = "1"
2024-09-23 00:23:07 -07:00
2024-09-22 22:58:32 -07:00
2021-09-17 18:04:12 -07:00
# Test tweets with URLs
2024-08-26 12:21:46 -07:00
tw fetch_user RoninGreg
2021-09-17 18:04:12 -07:00
urls_count = $( sqlite3 twitter.db "select count(*) from urls" )
2024-08-26 12:21:46 -07:00
test " $( sqlite3 twitter.db "select * from tweets where id = 754686478521892864" ) " = "" # Check it's not already there
tw fetch_tweet_only https://twitter.com/RoninGreg/status/754686478521892864
2021-09-17 18:04:12 -07:00
urls_count_after = $( sqlite3 twitter.db "select count(*) from urls" )
test $urls_count_after = $(( $urls_count + 1 ))
2024-08-26 12:21:46 -07:00
test " $( sqlite3 twitter.db "select title from urls where tweet_id = 754686478521892864" ) " = "Left Wing Politician Faces Jail for Fake Neo-Nazi Knife Attack"
test $( sqlite3 twitter.db "select count(*) from urls where tweet_id = 754686478521892864" ) = "1"
thumbnail_name = $( sqlite3 twitter.db "select thumbnail_remote_url from urls where tweet_id = 754686478521892864" | grep -Po "(?<=/)[\w-]+(?=\?)" )
2021-10-10 15:06:39 -07:00
test -n " $thumbnail_name " # Not testing for what the thumbnail url is because it keeps changing
2021-09-17 18:04:12 -07:00
# Try to double-fetch it; shouldn't duplicate the URL
2024-08-26 12:21:46 -07:00
tw fetch_tweet_only https://twitter.com/RoninGreg/status/754686478521892864
2021-09-17 18:04:12 -07:00
urls_count_after_2x = $( sqlite3 twitter.db "select count(*) from urls" )
test $urls_count_after_2x = $urls_count_after
2021-09-17 20:11:36 -07:00
# Download the link's preview image
2024-08-26 12:21:46 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 754686478521892864" ) = "0"
test $( sqlite3 twitter.db "select is_content_downloaded from urls where tweet_id = 754686478521892864" ) = "0"
2022-10-15 15:06:06 -04:00
initial_link_preview_images_count = $( find link_preview_images -mindepth 2 | wc -l)
2024-08-26 12:21:46 -07:00
tw download_tweet_content 754686478521892864
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 754686478521892864" ) = "1"
test $( sqlite3 twitter.db "select is_content_downloaded from urls where tweet_id = 754686478521892864" ) = "1"
2022-10-15 15:06:06 -04:00
test $( find link_preview_images -mindepth 2 | wc -l) = " $(( initial_link_preview_images_count + 1 )) "
2024-07-14 12:49:03 -07:00
find link_preview_images | grep -P ${ thumbnail_name } \\ w*.\\ w+
2021-09-17 20:11:36 -07:00
2021-09-17 18:04:12 -07:00
2021-09-17 20:50:28 -07:00
# Test a tweet with a URL but no thumbnail
2021-10-10 15:13:32 -07:00
tw fetch_user Xirong7
tw fetch_tweet_only https://twitter.com/Xirong7/status/1413665734866186243
2021-09-17 20:50:28 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from urls where tweet_id = 1413665734866186243" ) = "0"
test $( sqlite3 twitter.db "select has_thumbnail from urls where tweet_id = 1413665734866186243" ) = "0"
2021-10-07 14:58:59 -07:00
initial_link_preview_images_count = $( find link_preview_images | wc -l) # Check that it doesn't change, since there's no thumbnail
2021-09-17 20:50:28 -07:00
tw download_tweet_content 1413665734866186243
test $( sqlite3 twitter.db "select is_content_downloaded from urls where tweet_id = 1413665734866186243" ) = "1"
2021-10-07 14:58:59 -07:00
test $( find link_preview_images | wc -l) = $initial_link_preview_images_count # Should be the same
2021-09-17 20:50:28 -07:00
2021-11-06 13:37:46 -07:00
# Test a tweet thread with tombstones
2023-06-21 13:26:18 -03:00
tw fetch_tweet https://twitter.com/CovfefeAnon/status/1454526270809726977
2024-12-09 11:52:17 -08:00
test $( sqlite3 twitter.db "select is_stub from tweets where id = 1454515503242829830" ) = 1
2023-06-21 13:26:18 -03:00
test $( sqlite3 twitter.db "select is_stub from tweets where id = 1454521424144654344" ) = 1
2024-12-09 11:52:17 -08:00
test $( sqlite3 twitter.db "select is_stub from tweets where id = 1454522147750260742" ) = 1
2023-06-21 13:26:18 -03:00
test $( sqlite3 twitter.db "select is_stub from tweets where id = 1454526270809726977" ) = 0
# Check that it downloaded the fetchable user's profile image
2025-01-18 20:38:32 -08:00
handle = " $( sqlite3 twitter.db "select handle from users where id like 1365863538393309184" ) "
test " $( find profile_images/${ handle } _profile* | wc -l) " -ne 0
2023-06-21 13:26:18 -03:00
# Test an expanding ("Show more") tweet
tw fetch_tweet https://twitter.com/PaulSkallas/status/1649600354747572225
test $( sqlite3 twitter.db "select is_expandable from tweets where id = 1649600354747572225" ) = 1
test $( sqlite3 twitter.db "select length(text) from tweets where id = 1649600354747572225" ) -gt 280
test " $( sqlite3 twitter.db "select text from tweets where id = 1649600354747572225" | tail -n 1) " = "A fitting ending to a time not worth saving"
2022-02-27 23:05:37 -08:00
2023-06-07 13:23:57 -03:00
2022-05-07 16:47:46 -07:00
# Test updating a tombstone (e.g., the QT-ing user is blocked but acct is not priv)
tw fetch_tweet https://twitter.com/michaelmalice/status/1479540552081326085
2024-11-06 22:11:19 -08:00
test " $( sqlite3 twitter.db "select tombstone_type is null, text from tweets where id = 1479540319410696192" ) " = "0|"
2022-05-07 16:47:46 -07:00
tw fetch_tweet_only 1479540319410696192 # Should remove the tombstone type and update the text
2024-11-06 22:11:19 -08:00
test " $( sqlite3 twitter.db "select tombstone_type is null, text from tweets where id = 1479540319410696192" ) " = "1|Eyyy! Look! Another one on my block list! Well done @michaelmalice, you silck person."
2022-05-07 16:47:46 -07:00
2021-09-17 20:50:28 -07:00
2023-06-07 13:23:57 -03:00
# Test no-clobbering of num_likes/num_retweets etc when a tweet gets deleted/tombstoned
2023-08-22 20:12:50 -03:00
# TODO: this tweet got deleted
# tw fetch_tweet 1489428890783461377 # Quoted tweet
# test "$(sqlite3 twitter.db "select tombstone_type from tweets where id = 1489428890783461377")" = "" # Should not be tombstoned
# test "$(sqlite3 twitter.db "select num_likes from tweets where id = 1489428890783461377")" -gt "50" # Should have some likes
# initial_vals=$(sqlite3 twitter.db "select num_likes, num_retweets, num_replies, num_quote_tweets from tweets where id = 1489428890783461377")
# tw fetch_tweet 1489432246452985857 # Quoting tweet
# test "$(sqlite3 twitter.db "select tombstone_type from tweets where id = 1489428890783461377")" -gt "0" # Should be hidden
# test "$(sqlite3 twitter.db "select num_likes, num_retweets, num_replies, num_quote_tweets from tweets where id = 1489428890783461377")" = "$initial_vals"
2023-06-07 13:23:57 -03:00
2022-02-27 23:14:30 -08:00
# Test a tweet thread with a deleted account; should generate a user with a fake ID
2022-03-22 13:28:42 -07:00
tw fetch_tweet https://twitter.com/CovfefeAnon/status/1365278017233313795
test $( sqlite3 twitter.db "select is_id_fake from users where handle = '_selfoptimizer'" ) = 1
test $( sqlite3 twitter.db "select count(*) from tweets where user_id = (select id from users where handle = '_selfoptimizer')" ) = 1
2022-02-27 23:14:30 -08:00
2024-06-10 17:55:19 -07:00
# Test a tweet which is itself from a deleted account
2024-07-14 12:52:07 -07:00
tw fetch_tweet https://x.com/agnisterion/status/1569727165268393986
test $( sqlite3 twitter.db "select is_stub, user_id = 0x4000000000000000 from tweets where id = 1569727165268393986" ) = "1|1"
2024-06-10 17:55:19 -07:00
2022-02-27 23:14:30 -08:00
2022-01-07 13:40:22 -05:00
# Test fetching a banned user
2022-01-07 16:23:02 -05:00
tw fetch_user nancytracker
2024-09-22 22:58:32 -07:00
test " $( sqlite3 twitter.db "select is_banned from users where handle='nancytracker'" ) " = "1"
2022-01-07 13:40:22 -05:00
2022-01-18 17:48:08 -08:00
# 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"
2022-02-26 16:22:00 -08:00
# Test following / unfollowing a user
test " $( sqlite3 twitter.db "select count(*) from users where is_followed = 1" ) " = "0"
tw follow michaelmalice
test " $( sqlite3 twitter.db "select handle from users where is_followed = 1" ) " = "michaelmalice"
2022-02-28 16:06:58 -08:00
2024-09-17 18:25:25 -07:00
# 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
# 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"
2022-02-26 16:22:00 -08:00
2023-02-05 20:29:57 -05:00
2023-02-17 13:07:12 -05:00
# When not logged in, age-restricted tweet should fail to fetch
tw fetch_user PandasAndVidya
tw fetch_tweet_only https://twitter.com/PandasAndVidya/status/1562714727968428032 || true # This one is expected to fail
test " $( sqlite3 twitter.db "select count(*) from tweets where id = 156271472796842803" ) " = = "0"
# Fetch an age-restricted tweet while logged in
2023-10-14 20:08:15 -03:00
tw fetch_tweet_only https://twitter.com/PandasAndVidya/status/1562714727968428032
2023-02-17 13:07:12 -05:00
test " $( sqlite3 twitter.db "select count(*) from tweets where id = 156271472796842803" ) " = = "0"
2023-02-05 20:29:57 -05:00
2023-03-16 17:50:36 -03:00
# Test that you can pass a session with the `.session` file extension too
2024-09-17 18:30:11 -07:00
tw --session Offline_Twatter.session fetch_user Offline_Twatter # Dummy operation
2023-03-16 17:50:36 -03:00
2023-06-03 07:35:09 -03:00
# Test search
2023-10-14 20:08:15 -03:00
tw search "from:michaelmalice constitution"
2024-05-30 00:03:54 -07:00
# Update 2024-05-30: the default search page doesn't paginate anymore
2024-06-10 18:33:59 -07:00
test $( sqlite3 twitter.db "select count(*) from tweets where user_id = 44067298 and text like '%constitution%'" ) -gt "5" # Not sure exactly how many
2023-06-03 07:35:09 -03:00
2023-06-26 13:39:51 -03:00
# Test fetching user Likes
2023-09-01 22:33:47 -03:00
tw fetch_user Offline_Twatter
2023-10-14 20:08:15 -03:00
tw get_user_likes Offline_Twatter
2023-06-26 14:59:41 -03:00
test $( sqlite3 twitter.db "select count(*) from likes" ) -ge "2"
2023-06-26 13:39:51 -03:00
test $( sqlite3 twitter.db "select count(*) from likes where tweet_id = 1671902735250124802" ) = "1"
2023-06-25 22:18:00 -03:00
# Test liking and unliking
2023-06-26 14:59:41 -03:00
tw fetch_tweet_only 1589023388676554753
test $( sqlite3 twitter.db "select count(*) from likes where tweet_id = 1589023388676554753 and user_id = (select id from users where handle like 'offline_twatter')" ) = "0"
2023-10-14 20:08:15 -03:00
tw like_tweet https://twitter.com/elonmusk/status/1589023388676554753
2023-06-26 14:59:41 -03:00
test $( sqlite3 twitter.db "select count(*) from likes where tweet_id = 1589023388676554753 and user_id = (select id from users where handle like 'offline_twatter')" ) = "1"
2023-10-14 20:08:15 -03:00
tw unlike_tweet https://twitter.com/elonmusk/status/1589023388676554753
2023-06-26 14:59:41 -03:00
# TODO: implement deleting a Like
# test $(sqlite3 twitter.db "select count(*) from likes where tweet_id = 1589023388676554753 and user_id = (select id from users where handle like 'offline_twatter')") = "0"
2023-06-25 22:18:00 -03:00
2024-05-28 21:55:42 -07:00
# Test fetching bookmarks
tw get_bookmarks
test $( sqlite3 twitter.db "select count(*) from bookmarks" ) -ge "2"
test $( sqlite3 twitter.db "select count(*) from bookmarks where tweet_id = 1762239926437843421" ) = "1"
2023-06-25 22:18:00 -03:00
2024-08-25 22:57:40 -07:00
# Test fetching notifications
tw get_notifications
test $( sqlite3 twitter.db "select count(*) from notifications" ) -ge "5"
2023-11-18 16:35:15 -08:00
# Test fetch inbox
test $( sqlite3 twitter.db "select count(*) from chat_rooms" ) = "0"
test $( sqlite3 twitter.db "select count(*) from chat_messages" ) = "0"
tw fetch_inbox
test $( sqlite3 twitter.db "select count(*) from chat_rooms" ) -ge "1"
2024-07-28 17:53:49 -07:00
test $( sqlite3 twitter.db "select count(*) from chat_messages where chat_room_id = '1458284524761075714-1488963321701171204'" ) -ge "1" # Apparently extremely variable how many you get from "inbox"
2023-11-18 16:35:15 -08:00
2024-05-28 21:55:42 -07:00
2023-11-19 10:41:45 -08:00
# Test fetch a DM conversation
tw fetch_dm "1458284524761075714-1488963321701171204"
2023-11-18 16:35:15 -08:00
2023-12-26 19:52:37 -06:00
# Test followers and followees
test $( sqlite3 twitter.db "select count(*) from follows" ) = "0"
tw get_followees Offline_Twatter
2024-12-09 15:03:48 -08:00
test $( sqlite3 twitter.db "select count(*) from follows where follower_id = 1488963321701171204" ) = "3"
2023-12-26 19:52:37 -06:00
test $( sqlite3 twitter.db "select count(*) from follows where followee_id = 1488963321701171204" ) = "0"
tw get_followers Offline_Twatter
test $( sqlite3 twitter.db "select count(*) from follows where follower_id = 1488963321701171204 and followee_id = 759251" ) = "1"
2021-09-17 18:04:12 -07:00
# TODO: Maybe this file should be broken up into multiple test scripts
2021-08-05 14:10:46 -07:00
echo -e "\033[32mAll tests passed. Finished successfully.\033[0m"