diff --git a/ace-attorney-reddit-bot b/ace-attorney-reddit-bot index f268d7f..277c621 160000 --- a/ace-attorney-reddit-bot +++ b/ace-attorney-reddit-bot @@ -1 +1 @@ -Subproject commit f268d7f5d52965c95e6e6bd2fbd4c2880db8394a +Subproject commit 277c6211e5074f157e097c9c01cac4c22c622725 diff --git a/comment_list_brige.py b/comment_list_brige.py index 091163e..7e40efa 100644 --- a/comment_list_brige.py +++ b/comment_list_brige.py @@ -1,3 +1,5 @@ +import requests + class Comment: def __init__(self, tweet): self.author = Author(tweet.user.name) @@ -5,6 +7,14 @@ def __init__(self, tweet): if (len(self.body) == 0): self.body = '...' self.score = 0 + if (hasattr(tweet,'extended_entities') and tweet.extended_entities is not None + and 'media' in tweet.extended_entities and len(tweet.extended_entities['media']) > 0): + url = tweet.extended_entities['media'][0]['media_url_https'] + '?format=png&name=small' + name = tweet.extended_entities['media'][0]['media_url_https'].split('/')[-1] + '.png' + response = requests.get(url) + with open(name, 'wb') as file: + file.write(response.content) + self.evidence = name class Author: def __init__(self, name): diff --git a/main.py b/main.py index 4e3af4d..92c2e6a 100644 --- a/main.py +++ b/main.py @@ -131,7 +131,7 @@ def process_tweets(): except Exception as second_error: print(second_error) print(e) - os.remove(output_filename) + clean(thread, output_filename) else: try: api.update_status('@' + tweet.author.screen_name + " There should be at least two people in the conversation", in_reply_to_status_id=tweet.id_str) @@ -139,8 +139,22 @@ def process_tweets(): print(e) time.sleep(1) except Exception as e: + clean(thread, output_filename) print(e) + +def clean(thread, output_filename): + try: + os.remove(output_filename) + except Exception as second_e: + print(second_e) + try: + for comment in thread: + if (hasattr(comment, 'evidence')): + os.remove(comment.evidence) + except Exception as second_e: + print(second_e) + def restore_account(): global mention_queue global next_account