From 56737088ed86a6fa96e73a5580ab3e94c53d9751 Mon Sep 17 00:00:00 2001 From: GeneralHurricane Date: Fri, 13 Jan 2023 16:30:15 -0600 Subject: [PATCH] add common hashtags --- upload_top_scoring_link_to_twitter.py | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/upload_top_scoring_link_to_twitter.py b/upload_top_scoring_link_to_twitter.py index 2f4180b..75b9eac 100644 --- a/upload_top_scoring_link_to_twitter.py +++ b/upload_top_scoring_link_to_twitter.py @@ -1,4 +1,5 @@ from io import BytesIO +import random import re import tweepy from automeme import TextLine, get_rdrama, strip_markdown @@ -64,6 +65,14 @@ def hashtagify(string, api): input = re.sub(f" {hashtag} ", f" #{hashtag} ", input) return input +def add_common_hashtags(tweet, post): + post = post.lower() + for k, v in hashdict.items(): + if k in post: + ht = random.choice(v) + tweet = f"{tweet} {ht}" + return tweet + def get_tweet_text(post): rdrama_url = post['permalink'] title = post['title'] @@ -71,12 +80,12 @@ def get_tweet_text(post): text_space = TWEET_LENGTH - URL_LENGTH - 1 actual_title = re.sub(r":[^ ]*:", "", title) #remove marseys actual_title = hashtagify(actual_title, api) - if (len(title) > text_space): - actual_title = actual_title[0:text_space-3] + "..." - else: - actual_title = actual_title + actual_title = add_common_hashtags(actual_title, f"{title}\n{post['body']}") + if (len(actual_title) > text_space): + actual_title = actual_title[0:text_space-4] + "..." - return f"{actual_title} {rdrama_url}" + tweet = f"{actual_title} {rdrama_url}" + return tweet def post_top_scoring_link(rdrama, api): post = None @@ -94,5 +103,14 @@ def post_top_scoring_link(rdrama, api): url = f"https://twitter.com/drama_meme/status/{tweet.id}" rdrama.reply_to_post(post['id'], f"Nice post, bro! [I posted it to twitter]({url}).") +# dictionary of common popular topics and related hashtags +# search for the first phrase and choose one of the second +hashdict = { + 'terf mommy': ['#IStandWithJKRowling'], + 'rowling': ['#IStandWithJKRowling'], + 'hogwarts': ['#HogwartsLegacy'], + 'ukraine': ['#Ukraine'], +} + if __name__ == "__main__": - post_top_scoring_link(rdrama, api) \ No newline at end of file + post_top_scoring_link(rdrama, api)