From 653247989838c98e970c6207158c7c2e743da026 Mon Sep 17 00:00:00 2001 From: oloturia Date: Thu, 17 Dec 2020 01:31:57 +0100 Subject: [PATCH] Added configuration file, so it's possible to manage different profiles. Moved the images and the csvs in a different folder. --- config.json | 23 ++++++++ mastodon_main.py | 10 ++-- A00.png => oloturia/A00.png | Bin A01.png => oloturia/A01.png | Bin A02.png => oloturia/A02.png | Bin A03.png => oloturia/A03.png | Bin A04.png => oloturia/A04.png | Bin A05.png => oloturia/A05.png | Bin A06.png => oloturia/A06.png | Bin A07.png => oloturia/A07.png | Bin A08.png => oloturia/A08.png | Bin A09.png => oloturia/A09.png | Bin A10.png => oloturia/A10.png | Bin A11.png => oloturia/A11.png | Bin A12.png => oloturia/A12.png | Bin A13.png => oloturia/A13.png | Bin A14.png => oloturia/A14.png | Bin A15.png => oloturia/A15.png | Bin A16.png => oloturia/A16.png | Bin A17.png => oloturia/A17.png | Bin A18.png => oloturia/A18.png | Bin A19.png => oloturia/A19.png | Bin A20.png => oloturia/A20.png | Bin A21.png => oloturia/A21.png | Bin A22.png => oloturia/A22.png | Bin A23.png => oloturia/A23.png | Bin A24.png => oloturia/A24.png | Bin A25.png => oloturia/A25.png | Bin A26.png => oloturia/A26.png | Bin A27.png => oloturia/A27.png | Bin A28.png => oloturia/A28.png | Bin A29.png => oloturia/A29.png | Bin A30.png => oloturia/A30.png | Bin A31.png => oloturia/A31.png | Bin A32.png => oloturia/A32.png | Bin ART00.png => oloturia/ART00.png | Bin ART01.png => oloturia/ART01.png | Bin ART02.png => oloturia/ART02.png | Bin ART03.png => oloturia/ART03.png | Bin ARTO01.png => oloturia/ARTO01.png | Bin ARTO02.png => oloturia/ARTO02.png | Bin ARTO03.png => oloturia/ARTO03.png | Bin ARTO04.png => oloturia/ARTO04.png | Bin ARTO05.png => oloturia/ARTO05.png | Bin ARTO06.png => oloturia/ARTO06.png | Bin ARTO07.png => oloturia/ARTO07.png | Bin ARTO08.png => oloturia/ARTO08.png | Bin ARTO09.png => oloturia/ARTO09.png | Bin ARTO10.png => oloturia/ARTO10.png | Bin B00.0.png => oloturia/B00.0.png | Bin B00.1.png => oloturia/B00.1.png | Bin B00.2.png => oloturia/B00.2.png | Bin B00.3.png => oloturia/B00.3.png | Bin B01.png => oloturia/B01.png | Bin B02.png => oloturia/B02.png | Bin B03.png => oloturia/B03.png | Bin B04.png => oloturia/B04.png | Bin B05.png => oloturia/B05.png | Bin B06.png => oloturia/B06.png | Bin B07.png => oloturia/B07.png | Bin B08.png => oloturia/B08.png | Bin B09.0.png => oloturia/B09.0.png | Bin B09.1.png => oloturia/B09.1.png | Bin B10.png => oloturia/B10.png | Bin B11.png => oloturia/B11.png | Bin B12.png => oloturia/B12.png | Bin B13.png => oloturia/B13.png | Bin B14.png => oloturia/B14.png | Bin B15.png => oloturia/B15.png | Bin B16.png => oloturia/B16.png | Bin B20.png => oloturia/B20.png | Bin B21.0.png => oloturia/B21.0.png | Bin B21.1.png => oloturia/B21.1.png | Bin B21.2.png => oloturia/B21.2.png | Bin B22.png => oloturia/B22.png | Bin B23.png => oloturia/B23.png | Bin B24.png => oloturia/B24.png | Bin B25.0.png => oloturia/B25.0.png | Bin B25.1.png => oloturia/B25.1.png | Bin B26.0.png => oloturia/B26.0.png | Bin B26.1.png => oloturia/B26.1.png | Bin B27.png => oloturia/B27.png | Bin B28.png => oloturia/B28.png | Bin B29.png => oloturia/B29.png | Bin B30.png => oloturia/B30.png | Bin B31.png => oloturia/B31.png | Bin B32.png => oloturia/B32.png | Bin C01.png => oloturia/C01.png | Bin C02.png => oloturia/C02.png | Bin C03.png => oloturia/C03.png | Bin C04.png => oloturia/C04.png | Bin C05.png => oloturia/C05.png | Bin C06.png => oloturia/C06.png | Bin O00.0.png => oloturia/O00.0.png | Bin O00.1.png => oloturia/O00.1.png | Bin O00.2.png => oloturia/O00.2.png | Bin O00.3.png => oloturia/O00.3.png | Bin O01.png => oloturia/O01.png | Bin O02.png => oloturia/O02.png | Bin O04.png => oloturia/O04.png | Bin O05.png => oloturia/O05.png | Bin OBJ00.png => oloturia/OBJ00.png | Bin OBJ01.png => oloturia/OBJ01.png | Bin OBJ02.png => oloturia/OBJ02.png | Bin OBJ03.png => oloturia/OBJ03.png | Bin OBJ04.png => oloturia/OBJ04.png | Bin OBJ05.png => oloturia/OBJ05.png | Bin OBJ06.png => oloturia/OBJ06.png | Bin OBJ07.png => oloturia/OBJ07.png | Bin OBJ08.png => oloturia/OBJ08.png | Bin OBJ09.png => oloturia/OBJ09.png | Bin OBJ10.png => oloturia/OBJ10.png | Bin OBJ11.png => oloturia/OBJ11.png | Bin OBJ12.png => oloturia/OBJ12.png | Bin OBJ13.png => oloturia/OBJ13.png | Bin OBJ14.png => oloturia/OBJ14.png | Bin OBJ15.png => oloturia/OBJ15.png | Bin OBJ16.png => oloturia/OBJ16.png | Bin Q00.png => oloturia/Q00.png | Bin Q01.png => oloturia/Q01.png | Bin Q02.0.png => oloturia/Q02.0.png | Bin Q02.1.png => oloturia/Q02.1.png | Bin Q03.png => oloturia/Q03.png | Bin Q04.png => oloturia/Q04.png | Bin Q05.png => oloturia/Q05.png | Bin Q06.png => oloturia/Q06.png | Bin Q07.png => oloturia/Q07.png | Bin Q08.png => oloturia/Q08.png | Bin Q09.png => oloturia/Q09.png | Bin Q10.png => oloturia/Q10.png | Bin Q11.png => oloturia/Q11.png | Bin Q12.png => oloturia/Q12.png | Bin Q13.png => oloturia/Q13.png | Bin Q14.png => oloturia/Q14.png | Bin Q15.png => oloturia/Q15.png | Bin Q16.png => oloturia/Q16.png | Bin Q17.png => oloturia/Q17.png | Bin Q18.png => oloturia/Q18.png | Bin Q19.png => oloturia/Q19.png | Bin Q20.png => oloturia/Q20.png | Bin Q21.png => oloturia/Q21.png | Bin Q22.png => oloturia/Q22.png | Bin Q23.png => oloturia/Q23.png | Bin U00.png => oloturia/U00.png | Bin obj.csv => oloturia/obj.csv | 0 ram.csv => oloturia/ram.csv | 0 rtext.csv => oloturia/rtext.csv | 0 subs.csv => oloturia/subs.csv | 0 randstrip.py | 87 +++++++++++++++++++++--------- telegram_main.py | 10 ++-- twitter_main.py | 9 ++-- 151 files changed, 102 insertions(+), 37 deletions(-) create mode 100644 config.json rename A00.png => oloturia/A00.png (100%) rename A01.png => oloturia/A01.png (100%) rename A02.png => oloturia/A02.png (100%) rename A03.png => oloturia/A03.png (100%) rename A04.png => oloturia/A04.png (100%) rename A05.png => oloturia/A05.png (100%) rename A06.png => oloturia/A06.png (100%) rename A07.png => oloturia/A07.png (100%) rename A08.png => oloturia/A08.png (100%) rename A09.png => oloturia/A09.png (100%) rename A10.png => oloturia/A10.png (100%) rename A11.png => oloturia/A11.png (100%) rename A12.png => oloturia/A12.png (100%) rename A13.png => oloturia/A13.png (100%) rename A14.png => oloturia/A14.png (100%) rename A15.png => oloturia/A15.png (100%) rename A16.png => oloturia/A16.png (100%) rename A17.png => oloturia/A17.png (100%) rename A18.png => oloturia/A18.png (100%) rename A19.png => oloturia/A19.png (100%) rename A20.png => oloturia/A20.png (100%) rename A21.png => oloturia/A21.png (100%) rename A22.png => oloturia/A22.png (100%) rename A23.png => oloturia/A23.png (100%) rename A24.png => oloturia/A24.png (100%) rename A25.png => oloturia/A25.png (100%) rename A26.png => oloturia/A26.png (100%) rename A27.png => oloturia/A27.png (100%) rename A28.png => oloturia/A28.png (100%) rename A29.png => oloturia/A29.png (100%) rename A30.png => oloturia/A30.png (100%) rename A31.png => oloturia/A31.png (100%) rename A32.png => oloturia/A32.png (100%) rename ART00.png => oloturia/ART00.png (100%) rename ART01.png => oloturia/ART01.png (100%) rename ART02.png => oloturia/ART02.png (100%) rename ART03.png => oloturia/ART03.png (100%) rename ARTO01.png => oloturia/ARTO01.png (100%) rename ARTO02.png => oloturia/ARTO02.png (100%) rename ARTO03.png => oloturia/ARTO03.png (100%) rename ARTO04.png => oloturia/ARTO04.png (100%) rename ARTO05.png => oloturia/ARTO05.png (100%) rename ARTO06.png => oloturia/ARTO06.png (100%) rename ARTO07.png => oloturia/ARTO07.png (100%) rename ARTO08.png => oloturia/ARTO08.png (100%) rename ARTO09.png => oloturia/ARTO09.png (100%) rename ARTO10.png => oloturia/ARTO10.png (100%) rename B00.0.png => oloturia/B00.0.png (100%) rename B00.1.png => oloturia/B00.1.png (100%) rename B00.2.png => oloturia/B00.2.png (100%) rename B00.3.png => oloturia/B00.3.png (100%) rename B01.png => oloturia/B01.png (100%) rename B02.png => oloturia/B02.png (100%) rename B03.png => oloturia/B03.png (100%) rename B04.png => oloturia/B04.png (100%) rename B05.png => oloturia/B05.png (100%) rename B06.png => oloturia/B06.png (100%) rename B07.png => oloturia/B07.png (100%) rename B08.png => oloturia/B08.png (100%) rename B09.0.png => oloturia/B09.0.png (100%) rename B09.1.png => oloturia/B09.1.png (100%) rename B10.png => oloturia/B10.png (100%) rename B11.png => oloturia/B11.png (100%) rename B12.png => oloturia/B12.png (100%) rename B13.png => oloturia/B13.png (100%) rename B14.png => oloturia/B14.png (100%) rename B15.png => oloturia/B15.png (100%) rename B16.png => oloturia/B16.png (100%) rename B20.png => oloturia/B20.png (100%) rename B21.0.png => oloturia/B21.0.png (100%) rename B21.1.png => oloturia/B21.1.png (100%) rename B21.2.png => oloturia/B21.2.png (100%) rename B22.png => oloturia/B22.png (100%) rename B23.png => oloturia/B23.png (100%) rename B24.png => oloturia/B24.png (100%) rename B25.0.png => oloturia/B25.0.png (100%) rename B25.1.png => oloturia/B25.1.png (100%) rename B26.0.png => oloturia/B26.0.png (100%) rename B26.1.png => oloturia/B26.1.png (100%) rename B27.png => oloturia/B27.png (100%) rename B28.png => oloturia/B28.png (100%) rename B29.png => oloturia/B29.png (100%) rename B30.png => oloturia/B30.png (100%) rename B31.png => oloturia/B31.png (100%) rename B32.png => oloturia/B32.png (100%) rename C01.png => oloturia/C01.png (100%) rename C02.png => oloturia/C02.png (100%) rename C03.png => oloturia/C03.png (100%) rename C04.png => oloturia/C04.png (100%) rename C05.png => oloturia/C05.png (100%) rename C06.png => oloturia/C06.png (100%) rename O00.0.png => oloturia/O00.0.png (100%) rename O00.1.png => oloturia/O00.1.png (100%) rename O00.2.png => oloturia/O00.2.png (100%) rename O00.3.png => oloturia/O00.3.png (100%) rename O01.png => oloturia/O01.png (100%) rename O02.png => oloturia/O02.png (100%) rename O04.png => oloturia/O04.png (100%) rename O05.png => oloturia/O05.png (100%) rename OBJ00.png => oloturia/OBJ00.png (100%) rename OBJ01.png => oloturia/OBJ01.png (100%) rename OBJ02.png => oloturia/OBJ02.png (100%) rename OBJ03.png => oloturia/OBJ03.png (100%) rename OBJ04.png => oloturia/OBJ04.png (100%) rename OBJ05.png => oloturia/OBJ05.png (100%) rename OBJ06.png => oloturia/OBJ06.png (100%) rename OBJ07.png => oloturia/OBJ07.png (100%) rename OBJ08.png => oloturia/OBJ08.png (100%) rename OBJ09.png => oloturia/OBJ09.png (100%) rename OBJ10.png => oloturia/OBJ10.png (100%) rename OBJ11.png => oloturia/OBJ11.png (100%) rename OBJ12.png => oloturia/OBJ12.png (100%) rename OBJ13.png => oloturia/OBJ13.png (100%) rename OBJ14.png => oloturia/OBJ14.png (100%) rename OBJ15.png => oloturia/OBJ15.png (100%) rename OBJ16.png => oloturia/OBJ16.png (100%) rename Q00.png => oloturia/Q00.png (100%) rename Q01.png => oloturia/Q01.png (100%) rename Q02.0.png => oloturia/Q02.0.png (100%) rename Q02.1.png => oloturia/Q02.1.png (100%) rename Q03.png => oloturia/Q03.png (100%) rename Q04.png => oloturia/Q04.png (100%) rename Q05.png => oloturia/Q05.png (100%) rename Q06.png => oloturia/Q06.png (100%) rename Q07.png => oloturia/Q07.png (100%) rename Q08.png => oloturia/Q08.png (100%) rename Q09.png => oloturia/Q09.png (100%) rename Q10.png => oloturia/Q10.png (100%) rename Q11.png => oloturia/Q11.png (100%) rename Q12.png => oloturia/Q12.png (100%) rename Q13.png => oloturia/Q13.png (100%) rename Q14.png => oloturia/Q14.png (100%) rename Q15.png => oloturia/Q15.png (100%) rename Q16.png => oloturia/Q16.png (100%) rename Q17.png => oloturia/Q17.png (100%) rename Q18.png => oloturia/Q18.png (100%) rename Q19.png => oloturia/Q19.png (100%) rename Q20.png => oloturia/Q20.png (100%) rename Q21.png => oloturia/Q21.png (100%) rename Q22.png => oloturia/Q22.png (100%) rename Q23.png => oloturia/Q23.png (100%) rename U00.png => oloturia/U00.png (100%) rename obj.csv => oloturia/obj.csv (100%) rename ram.csv => oloturia/ram.csv (100%) rename rtext.csv => oloturia/rtext.csv (100%) rename subs.csv => oloturia/subs.csv (100%) diff --git a/config.json b/config.json new file mode 100644 index 0000000..e871e2a --- /dev/null +++ b/config.json @@ -0,0 +1,23 @@ +{ + "defaultProfile": "oloturia", + + "oloturia": { + "saveLocation": "/var/tmp", + "filename": "/image.png", + "imagesLocation": "./oloturia", + "csvLocation": "./oloturia", + "font": "./ubuntu.ttf", + "twitter": { + "token": "./twitter_token", + "filename": "/twitter.png" + }, + "mastodon": { + "token": "./mastodon_token", + "filename": "/mastodon.png" + }, + "telegram": { + "token": "./telegram_token", + "filename": "/telegram.png" + } + } +} diff --git a/mastodon_main.py b/mastodon_main.py index 6b2dafa..2cabc73 100755 --- a/mastodon_main.py +++ b/mastodon_main.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from randstrip import createStrip +from randstrip import createStrip,readConfig from mastodon import Mastodon import os @@ -8,17 +8,19 @@ fileDir = fileDir +"/" API_URL = "https://botsin.space" if __name__ == "__main__": - with open(fileDir+"mastodon_token") as f: + config = readConfig(platform="mastodon") + + with open(config["token"]) as f: createapp = f.readlines() createapp = [x.strip() for x in createapp] TOKEN = createapp[0] mastodon = Mastodon(access_token = TOKEN,api_base_url = API_URL) - status = createStrip("mastodon.png") + status = createStrip(config) if status == 0: published = False for i in range(1,100): try: - new_strip = mastodon.media_post(fileDir+"mastodon.png","image/png") + new_strip = mastodon.media_post(config["saveLocation"]+config["filename"],"image/png") mastodon.status_post("Nuova striscia",media_ids=new_strip) published = True except: diff --git a/A00.png b/oloturia/A00.png similarity index 100% rename from A00.png rename to oloturia/A00.png diff --git a/A01.png b/oloturia/A01.png similarity index 100% rename from A01.png rename to oloturia/A01.png diff --git a/A02.png b/oloturia/A02.png similarity index 100% rename from A02.png rename to oloturia/A02.png diff --git a/A03.png b/oloturia/A03.png similarity index 100% rename from A03.png rename to oloturia/A03.png diff --git a/A04.png b/oloturia/A04.png similarity index 100% rename from A04.png rename to oloturia/A04.png diff --git a/A05.png b/oloturia/A05.png similarity index 100% rename from A05.png rename to oloturia/A05.png diff --git a/A06.png b/oloturia/A06.png similarity index 100% rename from A06.png rename to oloturia/A06.png diff --git a/A07.png b/oloturia/A07.png similarity index 100% rename from A07.png rename to oloturia/A07.png diff --git a/A08.png b/oloturia/A08.png similarity index 100% rename from A08.png rename to oloturia/A08.png diff --git a/A09.png b/oloturia/A09.png similarity index 100% rename from A09.png rename to oloturia/A09.png diff --git a/A10.png b/oloturia/A10.png similarity index 100% rename from A10.png rename to oloturia/A10.png diff --git a/A11.png b/oloturia/A11.png similarity index 100% rename from A11.png rename to oloturia/A11.png diff --git a/A12.png b/oloturia/A12.png similarity index 100% rename from A12.png rename to oloturia/A12.png diff --git a/A13.png b/oloturia/A13.png similarity index 100% rename from A13.png rename to oloturia/A13.png diff --git a/A14.png b/oloturia/A14.png similarity index 100% rename from A14.png rename to oloturia/A14.png diff --git a/A15.png b/oloturia/A15.png similarity index 100% rename from A15.png rename to oloturia/A15.png diff --git a/A16.png b/oloturia/A16.png similarity index 100% rename from A16.png rename to oloturia/A16.png diff --git a/A17.png b/oloturia/A17.png similarity index 100% rename from A17.png rename to oloturia/A17.png diff --git a/A18.png b/oloturia/A18.png similarity index 100% rename from A18.png rename to oloturia/A18.png diff --git a/A19.png b/oloturia/A19.png similarity index 100% rename from A19.png rename to oloturia/A19.png diff --git a/A20.png b/oloturia/A20.png similarity index 100% rename from A20.png rename to oloturia/A20.png diff --git a/A21.png b/oloturia/A21.png similarity index 100% rename from A21.png rename to oloturia/A21.png diff --git a/A22.png b/oloturia/A22.png similarity index 100% rename from A22.png rename to oloturia/A22.png diff --git a/A23.png b/oloturia/A23.png similarity index 100% rename from A23.png rename to oloturia/A23.png diff --git a/A24.png b/oloturia/A24.png similarity index 100% rename from A24.png rename to oloturia/A24.png diff --git a/A25.png b/oloturia/A25.png similarity index 100% rename from A25.png rename to oloturia/A25.png diff --git a/A26.png b/oloturia/A26.png similarity index 100% rename from A26.png rename to oloturia/A26.png diff --git a/A27.png b/oloturia/A27.png similarity index 100% rename from A27.png rename to oloturia/A27.png diff --git a/A28.png b/oloturia/A28.png similarity index 100% rename from A28.png rename to oloturia/A28.png diff --git a/A29.png b/oloturia/A29.png similarity index 100% rename from A29.png rename to oloturia/A29.png diff --git a/A30.png b/oloturia/A30.png similarity index 100% rename from A30.png rename to oloturia/A30.png diff --git a/A31.png b/oloturia/A31.png similarity index 100% rename from A31.png rename to oloturia/A31.png diff --git a/A32.png b/oloturia/A32.png similarity index 100% rename from A32.png rename to oloturia/A32.png diff --git a/ART00.png b/oloturia/ART00.png similarity index 100% rename from ART00.png rename to oloturia/ART00.png diff --git a/ART01.png b/oloturia/ART01.png similarity index 100% rename from ART01.png rename to oloturia/ART01.png diff --git a/ART02.png b/oloturia/ART02.png similarity index 100% rename from ART02.png rename to oloturia/ART02.png diff --git a/ART03.png b/oloturia/ART03.png similarity index 100% rename from ART03.png rename to oloturia/ART03.png diff --git a/ARTO01.png b/oloturia/ARTO01.png similarity index 100% rename from ARTO01.png rename to oloturia/ARTO01.png diff --git a/ARTO02.png b/oloturia/ARTO02.png similarity index 100% rename from ARTO02.png rename to oloturia/ARTO02.png diff --git a/ARTO03.png b/oloturia/ARTO03.png similarity index 100% rename from ARTO03.png rename to oloturia/ARTO03.png diff --git a/ARTO04.png b/oloturia/ARTO04.png similarity index 100% rename from ARTO04.png rename to oloturia/ARTO04.png diff --git a/ARTO05.png b/oloturia/ARTO05.png similarity index 100% rename from ARTO05.png rename to oloturia/ARTO05.png diff --git a/ARTO06.png b/oloturia/ARTO06.png similarity index 100% rename from ARTO06.png rename to oloturia/ARTO06.png diff --git a/ARTO07.png b/oloturia/ARTO07.png similarity index 100% rename from ARTO07.png rename to oloturia/ARTO07.png diff --git a/ARTO08.png b/oloturia/ARTO08.png similarity index 100% rename from ARTO08.png rename to oloturia/ARTO08.png diff --git a/ARTO09.png b/oloturia/ARTO09.png similarity index 100% rename from ARTO09.png rename to oloturia/ARTO09.png diff --git a/ARTO10.png b/oloturia/ARTO10.png similarity index 100% rename from ARTO10.png rename to oloturia/ARTO10.png diff --git a/B00.0.png b/oloturia/B00.0.png similarity index 100% rename from B00.0.png rename to oloturia/B00.0.png diff --git a/B00.1.png b/oloturia/B00.1.png similarity index 100% rename from B00.1.png rename to oloturia/B00.1.png diff --git a/B00.2.png b/oloturia/B00.2.png similarity index 100% rename from B00.2.png rename to oloturia/B00.2.png diff --git a/B00.3.png b/oloturia/B00.3.png similarity index 100% rename from B00.3.png rename to oloturia/B00.3.png diff --git a/B01.png b/oloturia/B01.png similarity index 100% rename from B01.png rename to oloturia/B01.png diff --git a/B02.png b/oloturia/B02.png similarity index 100% rename from B02.png rename to oloturia/B02.png diff --git a/B03.png b/oloturia/B03.png similarity index 100% rename from B03.png rename to oloturia/B03.png diff --git a/B04.png b/oloturia/B04.png similarity index 100% rename from B04.png rename to oloturia/B04.png diff --git a/B05.png b/oloturia/B05.png similarity index 100% rename from B05.png rename to oloturia/B05.png diff --git a/B06.png b/oloturia/B06.png similarity index 100% rename from B06.png rename to oloturia/B06.png diff --git a/B07.png b/oloturia/B07.png similarity index 100% rename from B07.png rename to oloturia/B07.png diff --git a/B08.png b/oloturia/B08.png similarity index 100% rename from B08.png rename to oloturia/B08.png diff --git a/B09.0.png b/oloturia/B09.0.png similarity index 100% rename from B09.0.png rename to oloturia/B09.0.png diff --git a/B09.1.png b/oloturia/B09.1.png similarity index 100% rename from B09.1.png rename to oloturia/B09.1.png diff --git a/B10.png b/oloturia/B10.png similarity index 100% rename from B10.png rename to oloturia/B10.png diff --git a/B11.png b/oloturia/B11.png similarity index 100% rename from B11.png rename to oloturia/B11.png diff --git a/B12.png b/oloturia/B12.png similarity index 100% rename from B12.png rename to oloturia/B12.png diff --git a/B13.png b/oloturia/B13.png similarity index 100% rename from B13.png rename to oloturia/B13.png diff --git a/B14.png b/oloturia/B14.png similarity index 100% rename from B14.png rename to oloturia/B14.png diff --git a/B15.png b/oloturia/B15.png similarity index 100% rename from B15.png rename to oloturia/B15.png diff --git a/B16.png b/oloturia/B16.png similarity index 100% rename from B16.png rename to oloturia/B16.png diff --git a/B20.png b/oloturia/B20.png similarity index 100% rename from B20.png rename to oloturia/B20.png diff --git a/B21.0.png b/oloturia/B21.0.png similarity index 100% rename from B21.0.png rename to oloturia/B21.0.png diff --git a/B21.1.png b/oloturia/B21.1.png similarity index 100% rename from B21.1.png rename to oloturia/B21.1.png diff --git a/B21.2.png b/oloturia/B21.2.png similarity index 100% rename from B21.2.png rename to oloturia/B21.2.png diff --git a/B22.png b/oloturia/B22.png similarity index 100% rename from B22.png rename to oloturia/B22.png diff --git a/B23.png b/oloturia/B23.png similarity index 100% rename from B23.png rename to oloturia/B23.png diff --git a/B24.png b/oloturia/B24.png similarity index 100% rename from B24.png rename to oloturia/B24.png diff --git a/B25.0.png b/oloturia/B25.0.png similarity index 100% rename from B25.0.png rename to oloturia/B25.0.png diff --git a/B25.1.png b/oloturia/B25.1.png similarity index 100% rename from B25.1.png rename to oloturia/B25.1.png diff --git a/B26.0.png b/oloturia/B26.0.png similarity index 100% rename from B26.0.png rename to oloturia/B26.0.png diff --git a/B26.1.png b/oloturia/B26.1.png similarity index 100% rename from B26.1.png rename to oloturia/B26.1.png diff --git a/B27.png b/oloturia/B27.png similarity index 100% rename from B27.png rename to oloturia/B27.png diff --git a/B28.png b/oloturia/B28.png similarity index 100% rename from B28.png rename to oloturia/B28.png diff --git a/B29.png b/oloturia/B29.png similarity index 100% rename from B29.png rename to oloturia/B29.png diff --git a/B30.png b/oloturia/B30.png similarity index 100% rename from B30.png rename to oloturia/B30.png diff --git a/B31.png b/oloturia/B31.png similarity index 100% rename from B31.png rename to oloturia/B31.png diff --git a/B32.png b/oloturia/B32.png similarity index 100% rename from B32.png rename to oloturia/B32.png diff --git a/C01.png b/oloturia/C01.png similarity index 100% rename from C01.png rename to oloturia/C01.png diff --git a/C02.png b/oloturia/C02.png similarity index 100% rename from C02.png rename to oloturia/C02.png diff --git a/C03.png b/oloturia/C03.png similarity index 100% rename from C03.png rename to oloturia/C03.png diff --git a/C04.png b/oloturia/C04.png similarity index 100% rename from C04.png rename to oloturia/C04.png diff --git a/C05.png b/oloturia/C05.png similarity index 100% rename from C05.png rename to oloturia/C05.png diff --git a/C06.png b/oloturia/C06.png similarity index 100% rename from C06.png rename to oloturia/C06.png diff --git a/O00.0.png b/oloturia/O00.0.png similarity index 100% rename from O00.0.png rename to oloturia/O00.0.png diff --git a/O00.1.png b/oloturia/O00.1.png similarity index 100% rename from O00.1.png rename to oloturia/O00.1.png diff --git a/O00.2.png b/oloturia/O00.2.png similarity index 100% rename from O00.2.png rename to oloturia/O00.2.png diff --git a/O00.3.png b/oloturia/O00.3.png similarity index 100% rename from O00.3.png rename to oloturia/O00.3.png diff --git a/O01.png b/oloturia/O01.png similarity index 100% rename from O01.png rename to oloturia/O01.png diff --git a/O02.png b/oloturia/O02.png similarity index 100% rename from O02.png rename to oloturia/O02.png diff --git a/O04.png b/oloturia/O04.png similarity index 100% rename from O04.png rename to oloturia/O04.png diff --git a/O05.png b/oloturia/O05.png similarity index 100% rename from O05.png rename to oloturia/O05.png diff --git a/OBJ00.png b/oloturia/OBJ00.png similarity index 100% rename from OBJ00.png rename to oloturia/OBJ00.png diff --git a/OBJ01.png b/oloturia/OBJ01.png similarity index 100% rename from OBJ01.png rename to oloturia/OBJ01.png diff --git a/OBJ02.png b/oloturia/OBJ02.png similarity index 100% rename from OBJ02.png rename to oloturia/OBJ02.png diff --git a/OBJ03.png b/oloturia/OBJ03.png similarity index 100% rename from OBJ03.png rename to oloturia/OBJ03.png diff --git a/OBJ04.png b/oloturia/OBJ04.png similarity index 100% rename from OBJ04.png rename to oloturia/OBJ04.png diff --git a/OBJ05.png b/oloturia/OBJ05.png similarity index 100% rename from OBJ05.png rename to oloturia/OBJ05.png diff --git a/OBJ06.png b/oloturia/OBJ06.png similarity index 100% rename from OBJ06.png rename to oloturia/OBJ06.png diff --git a/OBJ07.png b/oloturia/OBJ07.png similarity index 100% rename from OBJ07.png rename to oloturia/OBJ07.png diff --git a/OBJ08.png b/oloturia/OBJ08.png similarity index 100% rename from OBJ08.png rename to oloturia/OBJ08.png diff --git a/OBJ09.png b/oloturia/OBJ09.png similarity index 100% rename from OBJ09.png rename to oloturia/OBJ09.png diff --git a/OBJ10.png b/oloturia/OBJ10.png similarity index 100% rename from OBJ10.png rename to oloturia/OBJ10.png diff --git a/OBJ11.png b/oloturia/OBJ11.png similarity index 100% rename from OBJ11.png rename to oloturia/OBJ11.png diff --git a/OBJ12.png b/oloturia/OBJ12.png similarity index 100% rename from OBJ12.png rename to oloturia/OBJ12.png diff --git a/OBJ13.png b/oloturia/OBJ13.png similarity index 100% rename from OBJ13.png rename to oloturia/OBJ13.png diff --git a/OBJ14.png b/oloturia/OBJ14.png similarity index 100% rename from OBJ14.png rename to oloturia/OBJ14.png diff --git a/OBJ15.png b/oloturia/OBJ15.png similarity index 100% rename from OBJ15.png rename to oloturia/OBJ15.png diff --git a/OBJ16.png b/oloturia/OBJ16.png similarity index 100% rename from OBJ16.png rename to oloturia/OBJ16.png diff --git a/Q00.png b/oloturia/Q00.png similarity index 100% rename from Q00.png rename to oloturia/Q00.png diff --git a/Q01.png b/oloturia/Q01.png similarity index 100% rename from Q01.png rename to oloturia/Q01.png diff --git a/Q02.0.png b/oloturia/Q02.0.png similarity index 100% rename from Q02.0.png rename to oloturia/Q02.0.png diff --git a/Q02.1.png b/oloturia/Q02.1.png similarity index 100% rename from Q02.1.png rename to oloturia/Q02.1.png diff --git a/Q03.png b/oloturia/Q03.png similarity index 100% rename from Q03.png rename to oloturia/Q03.png diff --git a/Q04.png b/oloturia/Q04.png similarity index 100% rename from Q04.png rename to oloturia/Q04.png diff --git a/Q05.png b/oloturia/Q05.png similarity index 100% rename from Q05.png rename to oloturia/Q05.png diff --git a/Q06.png b/oloturia/Q06.png similarity index 100% rename from Q06.png rename to oloturia/Q06.png diff --git a/Q07.png b/oloturia/Q07.png similarity index 100% rename from Q07.png rename to oloturia/Q07.png diff --git a/Q08.png b/oloturia/Q08.png similarity index 100% rename from Q08.png rename to oloturia/Q08.png diff --git a/Q09.png b/oloturia/Q09.png similarity index 100% rename from Q09.png rename to oloturia/Q09.png diff --git a/Q10.png b/oloturia/Q10.png similarity index 100% rename from Q10.png rename to oloturia/Q10.png diff --git a/Q11.png b/oloturia/Q11.png similarity index 100% rename from Q11.png rename to oloturia/Q11.png diff --git a/Q12.png b/oloturia/Q12.png similarity index 100% rename from Q12.png rename to oloturia/Q12.png diff --git a/Q13.png b/oloturia/Q13.png similarity index 100% rename from Q13.png rename to oloturia/Q13.png diff --git a/Q14.png b/oloturia/Q14.png similarity index 100% rename from Q14.png rename to oloturia/Q14.png diff --git a/Q15.png b/oloturia/Q15.png similarity index 100% rename from Q15.png rename to oloturia/Q15.png diff --git a/Q16.png b/oloturia/Q16.png similarity index 100% rename from Q16.png rename to oloturia/Q16.png diff --git a/Q17.png b/oloturia/Q17.png similarity index 100% rename from Q17.png rename to oloturia/Q17.png diff --git a/Q18.png b/oloturia/Q18.png similarity index 100% rename from Q18.png rename to oloturia/Q18.png diff --git a/Q19.png b/oloturia/Q19.png similarity index 100% rename from Q19.png rename to oloturia/Q19.png diff --git a/Q20.png b/oloturia/Q20.png similarity index 100% rename from Q20.png rename to oloturia/Q20.png diff --git a/Q21.png b/oloturia/Q21.png similarity index 100% rename from Q21.png rename to oloturia/Q21.png diff --git a/Q22.png b/oloturia/Q22.png similarity index 100% rename from Q22.png rename to oloturia/Q22.png diff --git a/Q23.png b/oloturia/Q23.png similarity index 100% rename from Q23.png rename to oloturia/Q23.png diff --git a/U00.png b/oloturia/U00.png similarity index 100% rename from U00.png rename to oloturia/U00.png diff --git a/obj.csv b/oloturia/obj.csv similarity index 100% rename from obj.csv rename to oloturia/obj.csv diff --git a/ram.csv b/oloturia/ram.csv similarity index 100% rename from ram.csv rename to oloturia/ram.csv diff --git a/rtext.csv b/oloturia/rtext.csv similarity index 100% rename from rtext.csv rename to oloturia/rtext.csv diff --git a/subs.csv b/oloturia/subs.csv similarity index 100% rename from subs.csv rename to oloturia/subs.csv diff --git a/randstrip.py b/randstrip.py index 7967060..9ad530a 100755 --- a/randstrip.py +++ b/randstrip.py @@ -5,29 +5,29 @@ from PIL import ImageDraw import csv import random import os +import json fileDir = os.path.dirname(os.path.abspath(__file__)) -fileDir = fileDir +"/" -def replaceText(text): +def replaceText(text,config): """This function replace $WILDCARD with a word found in subs.csv subs.csv definition is 1st colum $WILDCARD, subsequent columns, possible values (chosen at random), delimiter is ;""" - with open(fileDir+"subs.csv") as subs: + with open(config["csvLocation"]+"/"+"subs.csv") as subs: csvReader = csv.reader(subs,delimiter=";") for row in csvReader: if text.find(row[0]) != -1: text = text.replace(row[0],row[random.randint(1,len(row)-1)],1) return text -def fetchText(indText): +def fetchText(indText,config): """This function fetch the text for the image with two characters rtext.csv definition is: 1st column the name of the file (i.e. B001.png), 2nd number of actors (at the moment they are limited to two; then a couple of columns or each actor with x and y coord of the strings; after the coords the outcomes, one column for each actor Delimiter is ; and line feeds @, if there aren't any options, it returns 0 (no text) It returns two arrays, coords is a tuple (x,y) and result is the outcome""" - with open(fileDir+"rtext.csv") as rtext: + with open(config["csvLocation"]+"/rtext.csv") as rtext: csvReader = csv.reader(rtext,delimiter=';') for row in csvReader: if row[0]==indText: @@ -46,7 +46,7 @@ def fetchText(indText): return coords,result -def fetchVign(): +def fetchVign(config): """This functions fetch an image, randomly, chosen from a markov tree defined in ram.csv ram.csv definition is: 1st column the name of the image (without extension), subsequent columns, possible outcomes chosen randomly It returns an array with the file names""" @@ -55,7 +55,7 @@ def fetchVign(): nvign = 0 currVign = "000" story = [] - with open(fileDir+"ram.csv") as ram: + with open(config["csvLocation"]+"/ram.csv") as ram: csvReader = csv.reader(ram) for row in csvReader: starts.append(row[0]) @@ -70,44 +70,44 @@ def fetchVign(): print("tree with no END") quit() -def addThing(indVign): +def addThing(indVign,config): """This function adds a small image (object) to a larger image obj.csv definition is: name of the image (i.e. A001.png), x-coord, y-coord, subsequent columns possible outcomes It returns a tuple (object file name, x, y)""" - with open(fileDir+"obj.csv") as obj: + with open(config["csvLocation"]+"/obj.csv") as obj: csvReader = csv.reader(obj) for row in csvReader: if row[0] == indVign: return row[random.randint(3,len(row)-1)],row[1],row[2] return 0 -def writeStrip(story,fontSize): +def writeStrip(story,fontSize,config): """This function creates the strip returning an image object that could be saved or viewed. It takes an array with filenames as parameter The first image is always 000, then appends to strip the files, then decorates it fetching text and adding objects. If the object is an R, then repeats the last object.""" strip = [] for indVign in story: try: - vign = Image.open(fileDir+indVign).convert('RGBA') + vign = Image.open(config["imagesLocation"]+"/"+indVign).convert('RGBA') addtext = ImageDraw.Draw(vign) - fnt = ImageFont.truetype(fileDir+"ubuntu.ttf",fontSize) - textVign = fetchText(indVign) + fnt = ImageFont.truetype(config["font"],fontSize) + textVign = fetchText(indVign,config) if textVign!=0: for x in range(len(textVign[0])): text_vign = textVign[1][x] while text_vign.find('$') != -1: - text_vign = replaceText(text_vign) + text_vign = replaceText(text_vign,config) text_vign = text_vign.replace('@','\n') addtext.multiline_text((int(textVign[0][x][0]),int(textVign[0][x][1])),text_vign,fill="#000000",font=fnt,align="center") - obj = addThing(indVign) + obj = addThing(indVign,config) if obj!=0: if obj[0] == 'R': - objImg = Image.open(fileDir+prevObj[0]) + objImg = Image.open(config["imagesLocation"]+"/"+prevObj[0]) else: prevObj = obj - objImg = Image.open(fileDir+obj[0]) + objImg = Image.open(config["imagesLocation"]+"/"+obj[0]) vign.paste(objImg,(int(obj[1]),int(obj[2]))) strip.append(vign) except FileNotFoundError: @@ -119,38 +119,75 @@ def writeStrip(story,fontSize): xshift += 600 return image -def createStrip(name,fontSize=22): +def createStrip(config,specialPlatform="",fontSize=22): """Create strip and save it createStrip(str path/filename)""" try: - story = fetchVign() - finalStrip = writeStrip(story,fontSize) - if name == "android": + story = fetchVign(config) + finalStrip = writeStrip(story,fontSize,config) + if specialPlatform == "android": return finalStrip else: - finalStrip.save(fileDir+name) + finalStrip.save(config["saveLocation"]+config["filename"]) return 0 except Exception as err: return err +def readConfig(profile=False,platform=False): + """Read configuration file""" + try: + with open(fileDir+"/config.json") as f: + config = json.load(f) + except IOError: + print("config.json not found") + return False + if not(profile): + profile = config["defaultProfile"] + else: + profile = profile[0] + try: + checkProfile = config[profile] + except KeyError: + print("Profile not found") + quit() + saveLocation = checkLocal(config[profile]["saveLocation"]) + imagesLocation = checkLocal(config[profile]["imagesLocation"]) + csvLocation = checkLocal(config[profile]["csvLocation"]) + font = checkLocal(config[profile]["font"]) + 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} + filename = config[profile]["filename"] + return {"saveLocation":saveLocation,"imagesLocation":imagesLocation,"csvLocation":csvLocation,"font":font,"filename":filename} + +def checkLocal(directory): + """Checks if it's a relative or absolute path""" + if directory[0] == ".": + return fileDir + directory[1:] + else: + return directory + + if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument('-s','--story',metavar='story',default='',nargs=4,help='name of the images') parser.add_argument('-m','--multiple',metavar='multiple',default=[1],nargs=1,type=int,help='multiple output (int >0)') parser.add_argument('-x','--xsize',metavar='xsize',default=0,type=int,nargs=1,help='resize image x') + parser.add_argument('-p','--profile',metavar='profile',default="",type=str,nargs=1,help='profile') args = parser.parse_args() if args.multiple[0] <= 0: quit() + config = readConfig(profile=args.profile) for x in range(0,args.multiple[0]): if (args.story == ''): - story = fetchVign() + story = fetchVign(config) else: story = [] for x in args.story: story.append(x) - print(story) - finalStrip = writeStrip(story,22) + finalStrip = writeStrip(story,22,config) if args.multiple[0] == 1: if args.xsize == 0: finalStrip.show() diff --git a/telegram_main.py b/telegram_main.py index b5b76ad..941e8da 100755 --- a/telegram_main.py +++ b/telegram_main.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 from telegram.ext import Updater, CommandHandler -from randstrip import createStrip +from randstrip import createStrip,readConfig import requests import os @@ -8,10 +8,11 @@ fileDir = os.path.dirname(os.path.abspath(__file__)) fileDir = fileDir +"/" def newStrip(bot, update): - status = createStrip("telegram.png") + config = readConfig(platform="telegram") + status = createStrip(config) if status == 0: try: - bot.send_photo(chat_id=update.message.chat_id,photo=open(fileDir+"telegram.png","rb")) + bot.send_photo(chat_id=update.message.chat_id,photo=open(config["saveLocation"]+config["filename"],"rb")) except Exception as err: print(err) else: @@ -19,7 +20,8 @@ def newStrip(bot, update): print(status) if __name__ == "__main__": - with open(fileDir+"telegram_token") as token_file: + config = readConfig(platform="telegram") + with open(config["token"]) as token_file: content = token_file.readlines() token = content[0].strip() updater = Updater(token) diff --git a/twitter_main.py b/twitter_main.py index c3c5cfe..0277fd3 100755 --- a/twitter_main.py +++ b/twitter_main.py @@ -1,15 +1,16 @@ #!/usr/bin/env python3 import tweepy -from randstrip import createStrip +from randstrip import createStrip,readConfig import os fileDir = os.path.dirname(os.path.abspath(__file__)) fileDir = fileDir +"/" if __name__ == "__main__": - status = createStrip("twitter.png") + config = readConfig(platform="twitter") + status = createStrip(config) if status == 0: - with open(fileDir+"twitter_token") as f: + with open(config["token"]) as f: tokens = f.readlines() tokens = [x.strip() for x in tokens] auth = tweepy.OAuthHandler(tokens[0],tokens[1]) @@ -19,7 +20,7 @@ if __name__ == "__main__": for i in range(0,100): try: api.verify_credentials() - api.update_with_media(fileDir+"twitter.png","Generatore automatico di strip. Striscia di oggi.") + api.update_with_media(config["saveLocation"]+config["filename"],"Generatore automatico di strip. Striscia di oggi.") published = True except: continue