From 5bcb7a627893dc2352135e5b72129eebc282c48d Mon Sep 17 00:00:00 2001 From: d0c Date: Sun, 24 Jan 2021 13:33:16 +0100 Subject: [PATCH] newline issue solved --- .gitignore | 3 +++ env.sample | 2 +- megafono.py | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8daf2c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +.vscode/ +txt/* diff --git a/env.sample b/env.sample index 4a28b84..a9baee7 100644 --- a/env.sample +++ b/env.sample @@ -5,7 +5,7 @@ CLIENT_ID = '' CLIENT_SECRET = '' ACCESS_TOKEN = '' -# File with messages (one per line) to be tooted. Must be in txt directory. +# File with messages (one per line) to be tooted. Must be in 'txt' directory. ANNOUNCEMENT_FILE = 'es. announce.txt' # Set to 1 to enable random read from ANNOUNCEMENT_FILE diff --git a/megafono.py b/megafono.py index 7b41aef..12866c5 100644 --- a/megafono.py +++ b/megafono.py @@ -34,20 +34,20 @@ def megafono(): if int(RANDOM): import random - toot = random.choice(list(open(ANNOUNCEMENT_FILE, "r"))) + toot = random.choice(list(open(ANNOUNCEMENT_FILE, 'r'))) else: last_id = 0 with open(last_id_file) as f: last_id = int(f.read()) - with open(ANNOUNCEMENT_FILE, "r") as a: + with open(ANNOUNCEMENT_FILE, 'r', encoding='utf8') as a: toot = a.readlines()[last_id] - with open(ANNOUNCEMENT_FILE, "r") as a: + with open(ANNOUNCEMENT_FILE, 'r') as a: length = len(a.readlines()) last_id += 1 last_id %= length with open(last_id_file, 'w+') as f: f.write(str(last_id)) - mastodon.status_post(toot, visibility='unlisted') + mastodon.status_post(toot.replace('\\n','\n'), visibility='unlisted') print("Sent: "+str(toot))