diff --git a/README.md b/README.md index 5c5bd00..ea9876a 100644 --- a/README.md +++ b/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) } } } diff --git a/config.json b/config.json index d51a9f8..b5c38f5 100644 --- a/config.json +++ b/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" } } -} \ No newline at end of file +} diff --git a/mastodon_main.py b/mastodon_main.py index 2cabc73..e58e5b5 100755 --- a/mastodon_main.py +++ b/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 diff --git a/randstrip.py b/randstrip.py index 32a9a42..f02b7d4 100755 --- a/randstrip.py +++ b/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} diff --git a/twitter_main.py b/twitter_main.py index 0277fd3..251c432 100755 --- a/twitter_main.py +++ b/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