Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit ab212d4

Browse files
committed
Added the ability to show meda as evidence
1 parent 068627e commit ab212d4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ace-attorney-reddit-bot

comment_list_brige.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
import requests
2+
13
class Comment:
24
def __init__(self, tweet):
35
self.author = Author(tweet.user.name)
46
self.body = tweet.full_text
57
if (len(self.body) == 0):
68
self.body = '...'
79
self.score = 0
10+
if (hasattr(tweet,'extended_entities') and tweet.extended_entities is not None
11+
and 'media' in tweet.extended_entities and len(tweet.extended_entities['media']) > 0):
12+
url = tweet.extended_entities['media'][0]['media_url_https'] + '?format=png&name=small'
13+
name = tweet.extended_entities['media'][0]['media_url_https'].split('/')[-1] + '.png'
14+
response = requests.get(url)
15+
with open(name, 'wb') as file:
16+
file.write(response.content)
17+
self.evidence = name
818

919
class Author:
1020
def __init__(self, name):

main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,30 @@ def process_tweets():
131131
except Exception as second_error:
132132
print(second_error)
133133
print(e)
134-
os.remove(output_filename)
134+
clean(thread, output_filename)
135135
else:
136136
try:
137137
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)
138138
except Exception as e:
139139
print(e)
140140
time.sleep(1)
141141
except Exception as e:
142+
clean(thread, output_filename)
142143
print(e)
143144

145+
146+
def clean(thread, output_filename):
147+
try:
148+
os.remove(output_filename)
149+
except Exception as second_e:
150+
print(second_e)
151+
try:
152+
for comment in thread:
153+
if (hasattr(comment, 'evidence')):
154+
os.remove(comment.evidence)
155+
except Exception as second_e:
156+
print(second_e)
157+
144158
def restore_account():
145159
global mention_queue
146160
global next_account

0 commit comments

Comments
 (0)