add common hashtags
parent
22e2c11743
commit
56737088ed
|
@ -1,4 +1,5 @@
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
import tweepy
|
import tweepy
|
||||||
from automeme import TextLine, get_rdrama, strip_markdown
|
from automeme import TextLine, get_rdrama, strip_markdown
|
||||||
|
@ -64,6 +65,14 @@ def hashtagify(string, api):
|
||||||
input = re.sub(f" {hashtag} ", f" #{hashtag} ", input)
|
input = re.sub(f" {hashtag} ", f" #{hashtag} ", input)
|
||||||
return 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):
|
def get_tweet_text(post):
|
||||||
rdrama_url = post['permalink']
|
rdrama_url = post['permalink']
|
||||||
title = post['title']
|
title = post['title']
|
||||||
|
@ -71,12 +80,12 @@ def get_tweet_text(post):
|
||||||
text_space = TWEET_LENGTH - URL_LENGTH - 1
|
text_space = TWEET_LENGTH - URL_LENGTH - 1
|
||||||
actual_title = re.sub(r":[^ ]*:", "", title) #remove marseys
|
actual_title = re.sub(r":[^ ]*:", "", title) #remove marseys
|
||||||
actual_title = hashtagify(actual_title, api)
|
actual_title = hashtagify(actual_title, api)
|
||||||
if (len(title) > text_space):
|
actual_title = add_common_hashtags(actual_title, f"{title}\n{post['body']}")
|
||||||
actual_title = actual_title[0:text_space-3] + "..."
|
if (len(actual_title) > text_space):
|
||||||
else:
|
actual_title = actual_title[0:text_space-4] + "..."
|
||||||
actual_title = actual_title
|
|
||||||
|
|
||||||
return f"{actual_title} {rdrama_url}"
|
tweet = f"{actual_title} {rdrama_url}"
|
||||||
|
return tweet
|
||||||
|
|
||||||
def post_top_scoring_link(rdrama, api):
|
def post_top_scoring_link(rdrama, api):
|
||||||
post = None
|
post = None
|
||||||
|
@ -94,5 +103,14 @@ def post_top_scoring_link(rdrama, api):
|
||||||
url = f"https://twitter.com/drama_meme/status/{tweet.id}"
|
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}).")
|
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__":
|
if __name__ == "__main__":
|
||||||
post_top_scoring_link(rdrama, api)
|
post_top_scoring_link(rdrama, api)
|
Loading…
Reference in New Issue