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-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"
tw fetch_user Denlesks
test $( sqlite3 twitter.db "select count(*) from users" ) = "1"
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"
tw download_tweet_content 1261483383483293700
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"
test $( find videos| wc -l) = "1"
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-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-08-10 22:06:03 -07:00
# Download a user's profile image and banner image
2021-08-11 06:56:42 -07:00
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle = 'DiamondChariots'" ) = "0"
tw download_user_content DiamondChariots
test $( sqlite3 twitter.db "select is_content_downloaded from users where handle = 'DiamondChariots'" ) = "1"
test -f profile_images/DiamondChariots_profile_rE4OTedS.jpg
test -f profile_images/DiamondChariots_banner_1615811094.jpg
# Test that the `--profile` flag works
cd ..
tw --profile data fetch_user michaelmalice
test $( sqlite3 data/twitter.db "select count(*) from users where handle = 'michaelmalice'" ) = "1"
2021-08-10 22:06:03 -07:00
2021-08-05 14:10:46 -07:00
echo -e "\033[32mAll tests passed. Finished successfully.\033[0m"