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}): '
2021-08-07 17:06:39 -07:00
./compile.sh
2021-08-02 14:46:06 -07:00
test -e data && rm -r data
2021-08-11 06:56:42 -07:00
PATH = ` pwd ` :$PATH
tw create_profile data
cd data
2021-08-02 14:46:06 -07:00
# Fetch a user
2021-09-27 12:54:18 -07:00
test $( find profile_images | wc -l) = "1" # should be empty to begin
2021-08-11 06:56:42 -07:00
tw fetch_user Denlesks
test " $( sqlite3 twitter.db "select handle from users" ) " = "Denlesks"
test $( sqlite3 twitter.db "select count(*) from users" ) = "1"
2021-09-27 12:54:18 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle = 'Denlesks'" ) = "1"
test $( find profile_images | wc -l) = "3" # should have gotten 2 images
test -f profile_images/Denlesks_profile_22YJvhC7.jpg
test -f profile_images/Denlesks_banner_1585776052.jpg
tw fetch_user Denlesks # try to double-download it
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
2021-08-02 14:46:06 -07:00
# Fetch a tweet with images
2021-08-11 06:56:42 -07:00
tw fetch_tweet_only https://twitter.com/Denlesks/status/1261483383483293700
test $( sqlite3 twitter.db "select count(*) from tweets" ) = "1"
test " $( sqlite3 twitter.db "select text from tweets" ) " = "These are public health officials who are making decisions about your lifestyle because they know more about health, fitness and well-being than you do"
test $( sqlite3 twitter.db "select count(*) from images" ) = "4"
2021-08-07 17:06:39 -07:00
# Download its images
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1261483383483293700 and is_downloaded = 0" ) = "4"
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1261483383483293700 and is_downloaded = 1" ) = "0"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1261483383483293700" ) = "0"
test $( find images | wc -l) = "1"
2021-09-27 13:49:17 -07:00
tw download_tweet_content https://twitter.com/Denlesks/status/1261483383483293700
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1261483383483293700 and is_downloaded = 0" ) = "0"
test $( sqlite3 twitter.db "select count(*) from images where tweet_id = 1261483383483293700 and is_downloaded = 1" ) = "4"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1261483383483293700" ) = "1"
test $( find images | wc -l) = "5"
2021-08-05 14:10:46 -07:00
# Try to double-download it
2021-08-11 06:56:42 -07:00
tw fetch_tweet_only https://twitter.com/Denlesks/status/1261483383483293700
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
2021-08-11 06:56:42 -07:00
tw fetch_user DiamondChariots
test $( sqlite3 twitter.db "select handle from users" | wc -l) = "2"
tw fetch_tweet_only https://twitter.com/DiamondChariots/status/1418971605674467340
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
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1418971605674467340 and is_downloaded = 0" ) = "1"
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1418971605674467340 and is_downloaded = 1" ) = "0"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1418971605674467340" ) = "0"
2021-12-23 15:12:01 -05:00
test $( find videos | wc -l) = "1"
test $( find video_thumbnails | wc -l) = "1"
2021-08-11 06:56:42 -07:00
tw download_tweet_content 1418971605674467340
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1418971605674467340 and is_downloaded = 0" ) = "0"
test $( sqlite3 twitter.db "select count(*) from videos where tweet_id = 1418971605674467340 and is_downloaded = 1" ) = "1"
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1418971605674467340" ) = "1"
test $( find videos | wc -l) = "2"
2021-12-23 15:12:01 -05:00
test $( find video_thumbnails | wc -l) = "2"
2021-08-05 14:10:46 -07:00
# Try to double-download it
2021-08-11 06:56:42 -07:00
tw fetch_tweet_only https://twitter.com/DiamondChariots/status/1418971605674467340
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
initial_videos_count = $( find videos | wc -l)
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
test $( find videos | wc -l) = " $(( initial_videos_count)) " # Shouldn't have changed yet
tw download_tweet_content https://twitter.com/Cernovich/status/1444429517020274693
test $( find videos | wc -l) = " $(( initial_videos_count + 1 )) "
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"
2021-12-20 15:27:59 -05:00
test $( sqlite3 twitter.db "select is_conversation_scraped, abs(last_scraped_at - strftime('%s','now')) < 30 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"
2021-11-01 16:04:53 -07:00
# test $(sqlite3 twitter.db "select handle from tweets join users on tweets.user_id = users.id where tweets.id=1429583672827465730") = "kanesays23" TODO: 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
2021-08-11 06:56:42 -07:00
# Test that the `--profile` flag works
cd ..
2021-08-22 17:55:21 -07:00
tw --profile data fetch_user elonmusk
test $( sqlite3 data/twitter.db "select count(*) from users where handle = 'elonmusk'" ) = "1"
2021-08-19 12:54:08 -07:00
cd data
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
malice_id = $( sqlite3 twitter.db "select id from users where handle='michaelmalice'" )
test $( sqlite3 twitter.db "select count(*) from retweets" ) = "0"
tweet_count_1 = $( sqlite3 twitter.db "select count(*) from tweets" )
tw get_user_tweets michaelmalice
# Check that there are some retweets
rts_count = $( sqlite3 twitter.db "select count(*) from retweets" )
test $rts_count -gt "0"
# Check that new retweets plus new tweets > 50
tweet_count_2 = $( sqlite3 twitter.db "select count(*) from tweets" )
test $( sqlite3 twitter.db " select count(*) from retweets where retweeted_by != $malice_id " ) = "0"
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
tw fetch_user HbdNrx
test $( sqlite3 twitter.db "select is_private from users where handle = 'HbdNrx'" ) = "1"
2021-09-17 18:04:12 -07:00
# Test tweets with URLs
2021-10-10 15:13:32 -07:00
tw fetch_user CovfefeAnon
2021-09-17 18:04:12 -07:00
urls_count = $( sqlite3 twitter.db "select count(*) from urls" )
2021-10-10 15:13:32 -07:00
tw fetch_tweet_only https://twitter.com/CovfefeAnon/status/1428904664645394433
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 ))
test " $( sqlite3 twitter.db "select title from urls where tweet_id = 1428904664645394433" ) " = "Justice Department investigating Elon Musk's SpaceX following complaint of hiring discrimination"
2021-10-10 15:06:39 -07:00
test $( sqlite3 twitter.db "select count(*) from urls where tweet_id = 1428904664645394433" ) = "1"
2021-11-06 13:37:46 -07:00
thumbnail_name = $( sqlite3 twitter.db "select thumbnail_remote_url from urls where tweet_id = 1428904664645394433" | 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
2021-10-10 15:13:32 -07:00
tw fetch_tweet_only https://twitter.com/CovfefeAnon/status/1428904664645394433
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
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1428904664645394433" ) = "0"
test $( sqlite3 twitter.db "select is_content_downloaded from urls where tweet_id = 1428904664645394433" ) = "0"
2021-10-07 14:58:59 -07:00
initial_link_preview_images_count = $( find link_preview_images | wc -l)
2021-09-17 20:11:36 -07:00
tw download_tweet_content 1428904664645394433
test $( sqlite3 twitter.db "select is_content_downloaded from tweets where id = 1428904664645394433" ) = "1"
test $( sqlite3 twitter.db "select is_content_downloaded from urls where tweet_id = 1428904664645394433" ) = "1"
2021-10-07 14:58:59 -07:00
test $( find link_preview_images | wc -l) = " $(( initial_link_preview_images_count + 1 )) "
2021-10-10 15:06:39 -07:00
test -f link_preview_images/${ thumbnail_name } _800x320_1.jpg
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
2021-12-12 16:14:11 -08:00
# 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
2021-09-17 20:50:28 -07:00
2021-11-06 14:50:39 -07:00
# Test search
tw search "from:michaelmalice constitution"
test $( sqlite3 twitter.db "select count(*) from tweets where user_id = 44067298 and text like '%constitution%'" ) -gt "30" # Not sure exactly how many
2021-12-12 18:42:27 -08:00
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"
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"