|
|
|
@ -122,6 +122,8 @@ def save_post_counts(counts): |
|
|
|
f.write('\n') |
|
|
|
f.write('\n') |
|
|
|
logging.info("Saved post counts to x_post_counts.json") |
|
|
|
logging.info("Saved post counts to x_post_counts.json") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
def generate_article_tweet(author, post, persona): |
|
|
|
def generate_article_tweet(author, post, persona): |
|
|
|
title = post["title"] |
|
|
|
title = post["title"] |
|
|
|
url = post["url"] |
|
|
|
url = post["url"] |
|
|
|
@ -147,6 +149,13 @@ def generate_article_tweet(author, post, persona): |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
tweet = response.choices[0].message.content.strip() |
|
|
|
tweet = response.choices[0].message.content.strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Post-generation check: Strip any emojis using regex |
|
|
|
|
|
|
|
tweet = re.sub(r'[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\U0001F700-\U0001F77F\U0001F780-\U0001F7FF\U0001F800-\U0001F8FF\U0001F900-\U0001F9FF\U0001FA00-\U0001FA6F\U0001FA70-\U0001FAFF\U00002702-\U000027B0\U000024C2-\U0001F251]', '', tweet).strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Optionally, strip "[Read more]" or similar phrases as an additional failsafe |
|
|
|
|
|
|
|
tweet = re.sub(r'\[Read more\]\(.*?\)|\bRead more\b', '', tweet).strip() |
|
|
|
|
|
|
|
|
|
|
|
if len(tweet) > 280: |
|
|
|
if len(tweet) > 280: |
|
|
|
tweet = tweet[:277] + "..." |
|
|
|
tweet = tweet[:277] + "..." |
|
|
|
|
|
|
|
|
|
|
|
|