Aggiorna 'indy.py'

aggiunto try catch
This commit is contained in:
jops 2021-07-20 06:32:43 +02:00
parent e4ed68acf2
commit 78959b3e64

19
indy.py
View file

@ -3,6 +3,7 @@ from datetime import datetime
import requests
import pause
import json
import traceback
data = json.load(open('sorted.json'))
@ -37,13 +38,17 @@ for post in data:
# MEDIA LINK URL
linkurl = "https://italy.indymedia.org/uploads/"
# IMAGES ONLY
if post['linked_file'].lower().find('jpg') >= 0 or \
post['linked_file'].lower().find('jpeg') >= 0 or \
post['linked_file'].lower().find('gif') >= 0:
response = requests.get("https://italy.indymedia.org/uploads/" + post['linked_file'])
with open('./tmp', 'wb') as f:
f.write(response.content)
media_id = mastodon.media_post('./tmp')
try:
if post['linked_file'].lower().find('jpg') >= 0 or \
post['linked_file'].lower().find('jpeg') >= 0 or \
post['linked_file'].lower().find('gif') >= 0:
response = requests.get("https://italy.indymedia.org/uploads/" + post['linked_file'])
with open('./tmp', 'wb') as f:
f.write(response.content)
media_id = mastodon.media_post('./tmp')
except Exception:
traceback.print_exc()
media_ids = [media_id] if media_id else []
out += 'LEGGI IL POST: '+url