diff --git a/src/twapi.py b/src/twapi.py index a7adb6a..f746b8e 100644 --- a/src/twapi.py +++ b/src/twapi.py @@ -130,6 +130,7 @@ class TwAPI: async def get_ttweet_image_media_id(self, ttweet): img = await util.create_ttweet_image(ttweet) + print(f"obtaining media id for {img}...") media = self.api.media_upload(img) return media.media_id @@ -151,41 +152,41 @@ class TwAPI: return False # main tweet: text + screenshot - try: - print("creating main QRT w/ screenshot...") - media_ids = [await self.get_ttweet_image_media_id(ttweet)] - twt_resp = await self.post_tweet( - text, media_ids=media_ids, quote_tweet_id=ttweet.tweet_id - ) - print("done") - except: - print( - "error occurred trying to create main tweet, falling back to URL-main + reply screencap format" - ) - traceback.print_exc() - try: - print("posting main tweet...") - twt_resp = await self.post_tweet(text, quote_tweet_id=ttweet.tweet_id) - print("done") - twt_id = twt_resp.data["id"] + # try: + print("creating main QRT w/ screenshot...") + media_ids = [await self.get_ttweet_image_media_id(ttweet)] + twt_resp = await self.post_tweet( + text, media_ids=media_ids, quote_tweet_id=ttweet.tweet_id + ) + print("done") + # except: + # print( + # "error occurred trying to create main tweet, falling back to URL-main + reply screencap format" + # ) + # traceback.print_exc() + # try: + # print("posting main tweet...") + # twt_resp = await self.post_tweet(text, quote_tweet_id=ttweet.tweet_id) + # print("done") + # twt_id = twt_resp.data["id"] - try: - print("creating reply img...", end="") - media_ids = [await self.get_ttweet_image_media_id(ttweet)] - print("posting reply tweet...", end="") - await self.post_tweet(reply_to_tweet=twt_id, media_ids=media_ids) - print("done") - except: - print("Had trouble posting reply image tweet.") - print("successfully posted ttweet!") - except tweepy.Forbidden as e: - if "duplicate content" in e.api_messages[0]: - print( - "Twitter says the TalentTweet is a duplicate; skipping error-free..." - ) - return False - else: - raise e + # try: + # print("creating reply img...", end="") + # media_ids = [await self.get_ttweet_image_media_id(ttweet)] + # print("posting reply tweet...", end="") + # await self.post_tweet(reply_to_tweet=twt_id, media_ids=media_ids) + # print("done") + # except: + # print("Had trouble posting reply image tweet.") + # print("successfully posted ttweet!") + # except tweepy.Forbidden as e: + # if "duplicate content" in e.api_messages[0]: + # print( + # "Twitter says the TalentTweet is a duplicate; skipping error-free..." + # ) + # return False + # else: + # raise e return True async def post_ttweet_by_id(self, id: int, dry_run=False): diff --git a/src/util.py b/src/util.py index f616ed6..44c7326 100644 --- a/src/util.py +++ b/src/util.py @@ -83,6 +83,7 @@ async def create_ttweet_image(ttweet): tc.driver_path = "/usr/bin/chromedriver" filename = working_path(file="img.png") img = None + print(f"Creating image for TalentTweet {ttweet.url()}") try: os.remove(filename) except: @@ -94,11 +95,12 @@ async def create_ttweet_image(ttweet): mode=4, night_mode=1, show_parent_tweets=True, - parent_tweets_limit=3 + #parent_tweets_limit=3 ) img = fix_aspect_ratio(img) - except: - print("unable to create tweet image") + except Exception as e: + print("ERROR: unable to create tweet image") + print(e) traceback.print_exc() return None