From 03e6c211207b1afd2a912a4b4a93eb041011d482 Mon Sep 17 00:00:00 2001 From: Alex Huddleston Date: Thu, 28 Feb 2019 18:54:47 -0600 Subject: [PATCH] Keep from echoing retweets/replies. Added reply field in tweet converter --- .../tweet_converter.cpython-37.pyc | Bin 816 -> 868 bytes lib/twitter/tweet_converter.py | 9 ++++-- tweet_echoer.py | 28 +++++------------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/twitter/__pycache__/tweet_converter.cpython-37.pyc b/lib/twitter/__pycache__/tweet_converter.cpython-37.pyc index 733061c5a5fe812e6145ecdac90f6b0e41ff19f7..8f1b0bd08ab32120b6bdfda91dc7e244094eaf8d 100644 GIT binary patch delta 379 zcmY*TO-sW-5Z&3>O&U!}6||KI#ZT(ZiwBVsM7#)|L`ABhG)o&>6WwgFh2+qG(6U!A z9=-Vw`akyK#UJ7(RnU3NzM1!C;eC)VQaZ6L6RAqa!{!;8mR#ou5K2%A9hBk;4EGZ_ zMH9HIrP}C5)L?BoKBy$xgW>D1`Wpsxjh<~l8Rou)m0Ro)4jBsqXGXJ3pu|dRu)}+1+JLk>b(iJ wMgRi=BgZP33Yj)nFjR8I(b$Sgby0_$Sy?TAp5-jDar_whgFbCwwZ*E@H;~g@?*IS* delta 298 zcmaFDwtArm7*I76WTBLfJ6#HBeove`-)YnZb*CibcDAQa_AOjcr4X5^gMqs9Uf zom|4`&BJz!DKq63OG;u%YSiS@jIzujnp~4VF)B&30iAM-Ej2GWKPB}RM`~V4W=Uph z@h#@`)RM_wOzNspyhW+WK;ih3^3>Fl;waAi(h?|>6-=*WDB_tsjVX-LYVunqNhdL8 uHby2!HbxFG6l3IK1c^ZSOpFphz7lg0AJ9@iO-3+X!~^6Y5xkTAn8g5J97cZt diff --git a/lib/twitter/tweet_converter.py b/lib/twitter/tweet_converter.py index be6a3f3..4e4d9de 100644 --- a/lib/twitter/tweet_converter.py +++ b/lib/twitter/tweet_converter.py @@ -14,7 +14,8 @@ def convert_tweets(tweets): 'retweet':('RT @' in tweet.text), 'text':str(tweet.text.encode('utf-8'))[1:], 'hashtags':tweet.entities.get('hashtags'), - 'mentions':tweet.entities.get('user_metions') + 'mentions':tweet.entities.get('user_metions'), + 'reply':(tweet.in_reply_to_status_id_str) }) except: @@ -25,7 +26,8 @@ def convert_tweets(tweets): 'retweet':('RT @' in tweet.full_text), 'text':str(tweet.full_text.encode('utf-8'))[1:], 'hashtags':tweet.entities.get('hashtags'), - 'mentions':tweet.entities.get('user_metions') + 'mentions':tweet.entities.get('user_metions'), + 'reply':(tweet.in_reply_to_status_id_str) }) except: @@ -35,7 +37,8 @@ def convert_tweets(tweets): 'retweet':True, 'text':str(tweet.retweeted_status.text.encode("utf-8"))[1:], 'hashtags':tweet.entities.get('hashtags'), - 'mentions':tweet.entities.get('user_metions') + 'mentions':tweet.entities.get('user_metions'), + 'reply':(tweet.in_reply_to_status_id_str) }) return outtweets \ No newline at end of file diff --git a/tweet_echoer.py b/tweet_echoer.py index caef23e..9a08b15 100644 --- a/tweet_echoer.py +++ b/tweet_echoer.py @@ -85,13 +85,13 @@ def echo_recent_tweets(screen_name): language=None, idempotency_key=None) ''' - - mastodon.status_post( - t['text'][1:-1], - visibility='public', - spoiler_text='Twitter Echo, I\'m not on Masto rn.' - ) - print(t['date'] + '\t' + t['text']) + if((not t['reply']) and (not t['retweet'])): + mastodon.status_post( + t['text'][1:-1], + visibility='public', + spoiler_text='Twitter Echo, I\'m not on Masto rn.' + ) + print(t['date'] + '\t' + t['text']) sleep(30) fresh_start = False @@ -100,16 +100,4 @@ def echo_recent_tweets(screen_name): if __name__ == '__main__': with open('users.txt', 'r') as f: for l in f: - echo_recent_tweets(l.rstrip()) - -# Clean these up - -''' -#write the csv -with open('%s_tweets.csv' % screen_name, 'w') as f: - writer = csv.writer(f) - writer.writerow(["id","created_at","retweet","text","hashtags","user_mentions"]) - writer.writerows(outtweets) - -pass -''' + echo_recent_tweets(l.rstrip()) \ No newline at end of file