Browse Source

images support

d0c 3 years ago
parent
commit
a0fbd9f91a
2 changed files with 9 additions and 4 deletions
  1. 1 1
      README.md
  2. 8 3
      megafono.py

+ 1 - 1
README.md

@@ -25,4 +25,4 @@ https://github.com/caffeinewriter/botvenon
 
 ## Todo
 
-1. Images support in toot
+1. User documentation

+ 8 - 3
megafono.py

@@ -39,7 +39,7 @@ def megafono():
         last_id = 0
         with open(last_id_file) as f:
             last_id = int(f.read())
-        with open(ANNOUNCEMENT_FILE, 'r', encoding='utf8') as a:
+        with open(ANNOUNCEMENT_FILE, 'r') as a:
             toot = a.readlines()[last_id]
         with open(ANNOUNCEMENT_FILE, 'r') as a:
             length = len(a.readlines())
@@ -47,8 +47,13 @@ def megafono():
         last_id %= length
         with open(last_id_file, 'w+') as f:
                 f.write(str(last_id))
-    mastodon.status_post(toot.replace('\\n','\n'),  visibility='unlisted')
-    print("Sent: "+str(toot))
+        
+    if toot.startswith('IMG='):
+        msg = toot.split(' ', 1)
+        img = mastodon.media_post(msg[0].split('=')[1], "image/jpeg") 
+        mastodon.status_post(msg[1].replace('\\n','\n'), media_ids=img['id'], visibility='unlisted')
+    else:       
+        mastodon.status_post(toot.replace('\\n','\n'), visibility='unlisted')
 
 
 megafono()