Two bug fixes

- Search is now authenticated only
- `fetch_tweet` and `search` subcommands now respect the `-n [number]` flag
This commit is contained in:
Alessio 2023-06-03 07:35:09 -03:00
parent a724f32470
commit af93f44ed2
3 changed files with 15 additions and 14 deletions

View File

@ -270,11 +270,6 @@ test $(sqlite3 twitter.db "select is_id_fake from users where handle = '_selfopt
test $(sqlite3 twitter.db "select count(*) from tweets where user_id = (select id from users where handle = '_selfoptimizer')") = 1
# 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
# Test fetching a banned user
rm profile_images/default_profile.png
tw fetch_user nancytracker
@ -322,6 +317,12 @@ test "$(sqlite3 twitter.db "select count(*) from tweets where id = 1562714727968
# Test that you can pass a session with the `.session` file extension too
tw --session Offline_Twatter.session list_followed > /dev/null # Dummy operation
# Test search
tw --session Offline_Twatter -n 1 search "from:michaelmalice constitution" # TODO: remove `-n 1` once the authenticated cursor bug is fixed
test $(sqlite3 twitter.db "select count(*) from tweets where user_id = 44067298 and text like '%constitution%'") -gt "30" # Not sure exactly how many
# TODO: Maybe this file should be broken up into multiple test scripts
echo -e "\033[32mAll tests passed. Finished successfully.\033[0m"

View File

@ -129,7 +129,7 @@ func main() {
case "fetch_tweet_only":
fetch_tweet_only(target)
case "fetch_tweet":
fetch_tweet_conversation(target)
fetch_tweet_conversation(target, *how_many)
case "get_user_tweets":
fetch_user_feed(target, *how_many)
case "get_user_tweets_all":
@ -137,7 +137,7 @@ func main() {
case "download_tweet_content":
download_tweet_content(target)
case "search":
search(target)
search(target, *how_many)
case "follow":
follow_user(target, true)
case "unfollow":
@ -230,13 +230,13 @@ func fetch_tweet_only(tweet_identifier string) {
* args:
* - tweet_url: e.g., "https://twitter.com/michaelmalice/status/1395882872729477131"
*/
func fetch_tweet_conversation(tweet_identifier string) {
func fetch_tweet_conversation(tweet_identifier string, how_many int) {
tweet_id, err := extract_id_from(tweet_identifier)
if err != nil {
die(err.Error(), false, -1)
}
trove, err := scraper.GetTweetFull(tweet_id)
trove, err := scraper.GetTweetFull(tweet_id, how_many)
if err != nil {
die(err.Error(), false, -1)
}
@ -293,8 +293,8 @@ func download_user_content(handle scraper.UserHandle) {
}
}
func search(query string) {
trove, err := scraper.Search(query, 1000)
func search(query string, how_many int) {
trove, err := scraper.Search(query, how_many)
if err != nil {
die(fmt.Sprintf("Error scraping search results: %s", err.Error()), false, -100)
}

View File

@ -238,15 +238,15 @@ func GetTweet(id TweetID) (Tweet, error) {
*
* returns: the tweet, list of its replies and context, and users associated with those replies
*/
func GetTweetFull(id TweetID) (trove TweetTrove, err error) {
func GetTweetFull(id TweetID, how_many int) (trove TweetTrove, err error) {
tweet_response, err := the_api.GetTweet(id, "")
if err != nil {
err = fmt.Errorf("Error getting tweet: %d\n %w", id, err)
return
}
if len(tweet_response.GlobalObjects.Tweets) < DEFAULT_MAX_REPLIES_EAGER_LOAD &&
if len(tweet_response.GlobalObjects.Tweets) < how_many &&
tweet_response.GetCursor() != "" {
err = the_api.GetMoreReplies(id, &tweet_response, DEFAULT_MAX_REPLIES_EAGER_LOAD)
err = the_api.GetMoreReplies(id, &tweet_response, how_many)
if err != nil {
err = fmt.Errorf("Error getting more tweet replies: %d\n %w", id, err)
return