Aggiorna 'indy.py'
aggiunto try catch
This commit is contained in:
parent
e4ed68acf2
commit
78959b3e64
1 changed files with 12 additions and 7 deletions
19
indy.py
19
indy.py
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue