Browse Source

daje di try/catch

les 2 years ago
parent
commit
4d014a3908
1 changed files with 19 additions and 20 deletions
  1. 19 20
      indy.py

+ 19 - 20
indy.py

@@ -33,24 +33,23 @@ for post in data:
   out = post['created'] +"\n\n"+post['heading']+"\n\n"
 
   # CHECK MEDIA LINK
-  media_id = False
-  if post['linked_file']:
-    # MEDIA LINK URL
-    linkurl = "https://italy.indymedia.org/uploads/"
-    # IMAGES ONLY
-    try:
+  try:
+    media_id = False
+    if post['linked_file']:
+      # 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')
-    except Exception:
-      traceback.print_exc()
-
-
-  media_ids = [media_id] if media_id else []
-  out += 'LEGGI IL POST: '+url
-  print(out)
-  mastodon.status_post(out, media_ids=media_ids)
+        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')
+
+    media_ids = [media_id] if media_id else []
+    out += 'LEGGI IL POST: '+url
+    print(out)
+    mastodon.status_post(out, media_ids=media_ids)
+  except Exception:
+    traceback.print_exc()