Browse Source

added text for post in Twitter and Mastodon

oloturia 3 years ago
parent
commit
c20f17ea32
5 changed files with 33 additions and 13 deletions
  1. 1 0
      README.md
  2. 9 5
      config.json
  3. 8 3
      mastodon_main.py
  4. 7 2
      randstrip.py
  5. 8 3
      twitter_main.py

+ 1 - 0
README.md

@@ -47,6 +47,7 @@ Configuration file is a JSON with this tree:
 		"application":{ 	special instruction for applications, like "twitter", "mastodon", "telegram"
 			"token"		token location
 			"filename"	filename used for the temporary image
+			"text"		text for the post on Twitter and Mastodon (optional)
 		}
 	}
 }

+ 9 - 5
config.json

@@ -16,11 +16,13 @@
 		"panelLength":600,
 		"twitter": {
 			"token": "./twitter_token",
-			"filename": "/twitter.png"
+			"filename": "/twitter.png",
+			"text": "Generatore automatico di strip. Striscia di oggi."
 		},
 		"mastodon": {
 			"token": "./mastodon_token",
-			"filename": "/mastodon.png"
+			"filename": "/mastodon.png",
+			"text": "Nuova striscia"
 		},
 		"telegram": {
 			"token": "./telegram_token",
@@ -46,11 +48,13 @@
 		"panelLength":600,
 		"twitter": {
 			"token": "./twitter_token",
-			"filename": "/twitter.png"
+			"filename": "/twitter.png",
+			"text": "Automatic comic strip generator."			
 		},
 		"mastodon": {
 			"token": "./mastodon_token",
-			"filename": "/mastodon.png"
+			"filename": "/mastodon.png",
+			"text": "New comic"			
 		},
 		"telegram": {
 			"token": "./telegram_token",
@@ -60,4 +64,4 @@
 			"filename": "android.png"
 		}
 	}	
-}
+}

+ 8 - 3
mastodon_main.py

@@ -1,14 +1,19 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
 from randstrip import createStrip,readConfig
 from mastodon import Mastodon
 import os
+import sys
 
 fileDir = os.path.dirname(os.path.abspath(__file__))
 fileDir = fileDir +"/"
 API_URL = "https://botsin.space"
 	
 if __name__ == "__main__":
-	config = readConfig(platform="mastodon")
+	if len(sys.argv) == 2:
+		altProfile = [sys.argv[1]]
+	else:
+		altProfile = False
+	config = readConfig(platform="mastodon",profile=altProfile)
 	
 	with open(config["token"]) as f:
 		createapp = f.readlines()
@@ -21,7 +26,7 @@ if __name__ == "__main__":
 		for i in range(1,100):
 			try:
 				new_strip = mastodon.media_post(config["saveLocation"]+config["filename"],"image/png")
-				mastodon.status_post("Nuova striscia",media_ids=new_strip)
+				mastodon.status_post(config["text"],media_ids=new_strip)
 				published = True
 			except:
 				continue

+ 7 - 2
randstrip.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
 from PIL import Image
 from PIL import ImageFont
 from PIL import ImageDraw
@@ -175,7 +175,12 @@ def readConfig(profile=False,platform=False):
 	if platform:
 		token = checkLocal(config[profile][platform]["token"])
 		filename = checkLocal(config[profile][platform]["filename"])
-		return {"saveLocation":saveLocation,"imagesLocation":imagesLocation,"csvLocation":csvLocation,"font":font,"token":token,"filename":filename,"xSize":xSize,"ySize":ySize,"panelLength":panelLength,"csvTree":csvTree,"csvSpeech":csvSpeech,"csvSubs":csvSubs,"csvObj":csvObj}
+		try:
+			text = config[profile][platform]["text"]
+		except KeyError:
+			postText = False
+		
+		return {"saveLocation":saveLocation,"imagesLocation":imagesLocation,"csvLocation":csvLocation,"font":font,"token":token,"filename":filename,"xSize":xSize,"ySize":ySize,"panelLength":panelLength,"csvTree":csvTree,"csvSpeech":csvSpeech,"csvSubs":csvSubs,"csvObj":csvObj,"text":text}
 	filename = config[profile]["filename"]
 	return {"saveLocation":saveLocation,"imagesLocation":imagesLocation,"csvLocation":csvLocation,"font":font,"filename":filename,"xSize":xSize,"ySize":ySize,"panelLength":panelLength,"csvTree":csvTree,"csvSpeech":csvSpeech,"csvSubs":csvSubs,"csvObj":csvObj}
 		

+ 8 - 3
twitter_main.py

@@ -1,13 +1,18 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
 import tweepy
 from randstrip import createStrip,readConfig
 import os
+import sys
 
 fileDir = os.path.dirname(os.path.abspath(__file__))
 fileDir = fileDir +"/"
 
 if __name__ == "__main__":
-	config = readConfig(platform="twitter")
+	if len(sys.argv) == 2:
+		altProfile = [sys.argv[1]]
+	else:
+		altProfile = False
+	config = readConfig(platform="twitter",profile=altProfile)
 	status = createStrip(config)
 	if status == 0:
 		with open(config["token"]) as f:
@@ -20,7 +25,7 @@ if __name__ == "__main__":
 		for i in range(0,100):
 			try:
 				api.verify_credentials()
-				api.update_with_media(config["saveLocation"]+config["filename"],"Generatore automatico di strip. Striscia di oggi.")
+				api.update_with_media(config["saveLocation"]+config["filename"],config["text"])
 				published = True
 			except:
 				continue