remove backup tweet format that excludes screenshot

This commit is contained in:
muskit
2024-04-21 16:05:37 -07:00
parent 0203578987
commit bfc9066617
2 changed files with 40 additions and 37 deletions
+29 -28
View File
@@ -130,6 +130,7 @@ class TwAPI:
async def get_ttweet_image_media_id(self, ttweet): async def get_ttweet_image_media_id(self, ttweet):
img = await util.create_ttweet_image(ttweet) img = await util.create_ttweet_image(ttweet)
print(f"obtaining media id for {img}...")
media = self.api.media_upload(img) media = self.api.media_upload(img)
return media.media_id return media.media_id
@@ -151,41 +152,41 @@ class TwAPI:
return False return False
# main tweet: text + screenshot # main tweet: text + screenshot
try: # try:
print("creating main QRT w/ screenshot...") print("creating main QRT w/ screenshot...")
media_ids = [await self.get_ttweet_image_media_id(ttweet)] media_ids = [await self.get_ttweet_image_media_id(ttweet)]
twt_resp = await self.post_tweet( twt_resp = await self.post_tweet(
text, media_ids=media_ids, quote_tweet_id=ttweet.tweet_id text, media_ids=media_ids, quote_tweet_id=ttweet.tweet_id
) )
print("done") print("done")
except: # except:
print( # print(
"error occurred trying to create main tweet, falling back to URL-main + reply screencap format" # "error occurred trying to create main tweet, falling back to URL-main + reply screencap format"
) # )
traceback.print_exc() # traceback.print_exc()
try: # try:
print("posting main tweet...") # print("posting main tweet...")
twt_resp = await self.post_tweet(text, quote_tweet_id=ttweet.tweet_id) # twt_resp = await self.post_tweet(text, quote_tweet_id=ttweet.tweet_id)
print("done") # print("done")
twt_id = twt_resp.data["id"] # twt_id = twt_resp.data["id"]
try: # try:
print("creating reply img...", end="") # print("creating reply img...", end="")
media_ids = [await self.get_ttweet_image_media_id(ttweet)] # media_ids = [await self.get_ttweet_image_media_id(ttweet)]
print("posting reply tweet...", end="") # print("posting reply tweet...", end="")
await self.post_tweet(reply_to_tweet=twt_id, media_ids=media_ids) # await self.post_tweet(reply_to_tweet=twt_id, media_ids=media_ids)
print("done") # print("done")
except: # except:
print("Had trouble posting reply image tweet.") # print("Had trouble posting reply image tweet.")
print("successfully posted ttweet!") # print("successfully posted ttweet!")
except tweepy.Forbidden as e: # except tweepy.Forbidden as e:
if "duplicate content" in e.api_messages[0]: # if "duplicate content" in e.api_messages[0]:
print( # print(
"Twitter says the TalentTweet is a duplicate; skipping error-free..." # "Twitter says the TalentTweet is a duplicate; skipping error-free..."
) # )
return False # return False
else: # else:
raise e # raise e
return True return True
async def post_ttweet_by_id(self, id: int, dry_run=False): async def post_ttweet_by_id(self, id: int, dry_run=False):
+5 -3
View File
@@ -83,6 +83,7 @@ async def create_ttweet_image(ttweet):
tc.driver_path = "/usr/bin/chromedriver" tc.driver_path = "/usr/bin/chromedriver"
filename = working_path(file="img.png") filename = working_path(file="img.png")
img = None img = None
print(f"Creating image for TalentTweet {ttweet.url()}")
try: try:
os.remove(filename) os.remove(filename)
except: except:
@@ -94,11 +95,12 @@ async def create_ttweet_image(ttweet):
mode=4, mode=4,
night_mode=1, night_mode=1,
show_parent_tweets=True, show_parent_tweets=True,
parent_tweets_limit=3 #parent_tweets_limit=3
) )
img = fix_aspect_ratio(img) img = fix_aspect_ratio(img)
except: except Exception as e:
print("unable to create tweet image") print("ERROR: unable to create tweet image")
print(e)
traceback.print_exc() traceback.print_exc()
return None return None