From 400e15d18afe03a30ccb98b74420e688d97ffc87 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sat, 13 Oct 2018 20:01:51 +0200 Subject: [PATCH 01/32] fix screenshot links in default city page --- user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user.py b/user.py index dad9b1c..fee172f 100644 --- a/user.py +++ b/user.py @@ -388,9 +388,9 @@ mentioned, und gib an Zum Beispiel so: -![Screenshot of writing a Toot](https://github.com/b3yond/ticketfrei/raw/master/guides/tooting_screenshot.png) +![Screenshot of writing a Toot](https://github.com/b3yond/ticketfrei/raw/stable1/guides/tooting_screenshot.png) -![A toot ready to be shared](https://github.com/b3yond/ticketfrei/raw/master/guides/toot_screenshot.png) +![A toot ready to be shared](https://github.com/b3yond/ticketfrei/raw/stable1/guides/toot_screenshot.png) Der Bot wird die Nachricht dann weiterverbreiten, auch zu den anderen Netzwerken. From 01f33ea29a3e5d1557828857fe1bd14848ebaaae Mon Sep 17 00:00:00 2001 From: b3yond Date: Thu, 18 Oct 2018 17:04:06 +0200 Subject: [PATCH 02/32] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 24 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 17 ++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..7c1e5b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,24 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Actual Behavior** +A clear and concise description of what happens. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..066b2d9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 651e68431665356200caa2b9d59b7468acf54f2e Mon Sep 17 00:00:00 2001 From: b3yond Date: Thu, 18 Oct 2018 17:09:21 +0200 Subject: [PATCH 03/32] add another issue template --- .github/ISSUE_TEMPLATE/something-else.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/something-else.md diff --git a/.github/ISSUE_TEMPLATE/something-else.md b/.github/ISSUE_TEMPLATE/something-else.md new file mode 100644 index 0000000..3d188cf --- /dev/null +++ b/.github/ISSUE_TEMPLATE/something-else.md @@ -0,0 +1,7 @@ +--- +name: Something else +about: Other ideas? + +--- + +*If your suggestion is neither a bug report nor a feature request, this is the right place. Just describe what you have in mind.* From 9508618347baf2d6e878321cd86d2563588c3542 Mon Sep 17 00:00:00 2001 From: git-sid <25916907+git-sid@users.noreply.github.com> Date: Fri, 19 Oct 2018 08:26:20 +0200 Subject: [PATCH 04/32] add rss feed notification option to info page --- user.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/user.py b/user.py index fee172f..45f0f70 100644 --- a/user.py +++ b/user.py @@ -361,10 +361,11 @@ Aber je mehr Leute mitmachen, desto eher kannst du dir sicher sein, dass wir sie finden, bevor sie uns finden. Wenn du immer direkt gewarnt werden willst, kannst du auch die -Benachrichtigungen über E-Mail oder Telegram aktivieren. Gib +Benachrichtigungen über E-Mail, Telegram, Mastodon und RSS feed aktivieren. Gib einfach hier deine -E-Mail-Adresse an oder subscribe dem Telegram-Bot [@ticketfrei_""" + city + \ - "_bot](https://t.me/ticketfrei_" + city + """_bot) +E-Mail-Adresse an, oder subscribe dem Telegram-Bot [@ticketfrei_""" + city +\ +"_bot](https://t.me/ticketfrei_" + city + """_bot), Mastodon-bot [@""" +\ +city + """](""" + masto_link + """"), oder RSS feed [""" + city + """](""" + masto_link + """.atom?replies=false&boosts=true) Also, wenn du weniger Glück hast, und der erste bist, der einen Kontrolleur sieht: From 7cb211b4cb7de1116c97e4afd6739ca48405f9aa Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 26 Oct 2018 17:25:25 +0200 Subject: [PATCH 05/32] polishing the wording of RSS subscription --- user.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/user.py b/user.py index 45f0f70..3158568 100644 --- a/user.py +++ b/user.py @@ -361,11 +361,13 @@ Aber je mehr Leute mitmachen, desto eher kannst du dir sicher sein, dass wir sie finden, bevor sie uns finden. Wenn du immer direkt gewarnt werden willst, kannst du auch die -Benachrichtigungen über E-Mail, Telegram, Mastodon und RSS feed aktivieren. Gib -einfach hier deine -E-Mail-Adresse an, oder subscribe dem Telegram-Bot [@ticketfrei_""" + city +\ -"_bot](https://t.me/ticketfrei_" + city + """_bot), Mastodon-bot [@""" +\ -city + """](""" + masto_link + """"), oder RSS feed [""" + city + """](""" + masto_link + """.atom?replies=false&boosts=true) +Benachrichtigungen über E-Mail, Telegram, oder den Mastodon RSS +feed aktivieren. Entweder: +* Gibt hier [deine E-Mail-Adresse an](/city/mail/""" + city + """) +* Subscribe dem Telegram-Bot [@ticketfrei_""" + city + \ +"_bot](https://t.me/ticketfrei_" + city + """_bot) +* oder subscribe dem RSS feed von [""" + city + """](""" + masto_link + \ +""".atom?replies=false&boosts=true) Also, wenn du weniger Glück hast, und der erste bist, der einen Kontrolleur sieht: From 8b36589557b0687a8419dfdbdbf9ae4ea885bdfa Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 26 Oct 2018 17:27:00 +0200 Subject: [PATCH 06/32] added 502 to unlogged Telegram error codes --- active_bots/telegrambot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 0bb2866..a65e38f 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -21,7 +21,7 @@ class TelegramBot(Bot): return reports for update in updates: # return when telegram returns an error code - if update in [303, 404, 420, 500]: + if update in [303, 404, 420, 500, 502]: return reports elif isinstance(update, int): logger.error("Unknown Telegram error code: " + str(update)) From 710a89c282565d5d78bbf855fa3cc8857df55cfc Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 26 Oct 2018 18:20:01 +0200 Subject: [PATCH 07/32] fix mailbot crash: File "/srv/ticketfrei/active_bots/mailbot.py", line 37, in post if rec not in report.author: TypeError: argument of type 'NoneType' is not iterable --- active_bots/telegrambot.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index a65e38f..385c32d 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -45,6 +45,10 @@ class TelegramBot(Bot): "Send reports here to share them with other users. Use /start and /stop to get reports or not.") # TODO: /help message should be set in frontend else: + # set report.author to "" to avoid mailbot crash + if update.message.sender.username is None: + update.message.sender.username = "" + reports.append(Report(update.message.sender.username, self, update.message.text, None, update.message.date)) From f274d258227ff8fc23ffdd6cee65f13a0ada1d33 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 6 Nov 2018 08:56:24 +0100 Subject: [PATCH 08/32] updated example config options + 1 little fix --- active_bots/telegrambot.py | 2 +- config.toml.example | 5 +---- sendmail.py | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 385c32d..1c3eae9 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -23,7 +23,7 @@ class TelegramBot(Bot): # return when telegram returns an error code if update in [303, 404, 420, 500, 502]: return reports - elif isinstance(update, int): + if isinstance(update, int): logger.error("Unknown Telegram error code: " + str(update)) return reports user.save_seen_tg(update.update_id) diff --git a/config.toml.example b/config.toml.example index d93c333..eb519db 100644 --- a/config.toml.example +++ b/config.toml.example @@ -10,10 +10,7 @@ port = 80 contact = "b3yond@riseup.net" [mail] -mailserver = "smtp.riseup.net" -user = "user" -passphrase = "sup3rs3cur3" -mbox = "root" +mbox_user = "root" [database] db_path = "/var/ticketfrei/db.sqlite" diff --git a/sendmail.py b/sendmail.py index dec722d..3c6e9a6 100755 --- a/sendmail.py +++ b/sendmail.py @@ -27,5 +27,5 @@ def sendmail(to, subject, city=None, body=''): # For testing: if __name__ == '__main__': - sendmail(config['mail']['contact'], "Test Mail", + sendmail(config['web']['contact'], "Test Mail", body="This is a test mail.") From 238dd20d207c9d98b9167bf202e6d9aa9cc34772 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 6 Nov 2018 16:17:47 +0100 Subject: [PATCH 09/32] if no config.toml, set config through environment #64 --- config.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index fa01302..abbae62 100755 --- a/config.py +++ b/config.py @@ -1,5 +1,57 @@ import pytoml as toml +import os + +def load_env(): + """ + load environment variables from the environment. If empty, use default + values from config.toml.example. + + :return: config dictionary of dictionaries. + """ + with open('config.toml.example') as defaultconf: + config = toml.load(configfile) + + try: + config['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] + except KeyError: + pass + + try: + config['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET'] + except KeyError: + pass + + try: + config['web']['host'] = os.environ['HOST'] + except KeyError: + pass + + try: + config['web']['port'] = os.environ['PORT'] + except KeyError: + pass + + try: + config['web']['contact'] = os.environ['CONTACT'] + except KeyError: + pass + + try: + config['mail']['mbox_user'] = os.environ['MBOX_USER'] + except KeyError: + pass + + try: + config['database']['db_path'] = os.environ['DB_PATH'] + except KeyError: + pass + + return config + # read config in TOML format (https://github.com/toml-lang/toml#toml) -with open('config.toml') as configfile: - config = toml.load(configfile) +try: + with open('config.toml') as configfile: + config = toml.load(configfile) +except FileNotFoundError: + config = load_env() From d964927a3f00ee392d8a29eeff85532faef7a32f Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 6 Nov 2018 16:22:11 +0100 Subject: [PATCH 10/32] fix small bug, print current config if directly called #64 --- config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index abbae62..4550b14 100755 --- a/config.py +++ b/config.py @@ -9,7 +9,7 @@ def load_env(): :return: config dictionary of dictionaries. """ with open('config.toml.example') as defaultconf: - config = toml.load(configfile) + config = toml.load(defaultconf) try: config['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] @@ -55,3 +55,8 @@ try: config = toml.load(configfile) except FileNotFoundError: config = load_env() + +if __name__ == "__main__": + for category in config: + for key in config[category]: + print(key + " = " + str(config[category][key])) From bc7a4a72f80c1c7a4822531579cc3e200cd306b6 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 6 Nov 2018 16:23:47 +0100 Subject: [PATCH 11/32] beauty overhaul of config.py --- config.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index 4550b14..2b8a6cb 100755 --- a/config.py +++ b/config.py @@ -1,6 +1,7 @@ import pytoml as toml import os + def load_env(): """ load environment variables from the environment. If empty, use default @@ -9,44 +10,44 @@ def load_env(): :return: config dictionary of dictionaries. """ with open('config.toml.example') as defaultconf: - config = toml.load(defaultconf) + configdict = toml.load(defaultconf) try: - config['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] + configdict['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] except KeyError: pass try: - config['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET'] + configdict['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET'] except KeyError: pass try: - config['web']['host'] = os.environ['HOST'] + configdict['web']['host'] = os.environ['HOST'] except KeyError: pass try: - config['web']['port'] = os.environ['PORT'] + configdict['web']['port'] = os.environ['PORT'] except KeyError: pass try: - config['web']['contact'] = os.environ['CONTACT'] + configdict['web']['contact'] = os.environ['CONTACT'] except KeyError: pass try: - config['mail']['mbox_user'] = os.environ['MBOX_USER'] + configdict['mail']['mbox_user'] = os.environ['MBOX_USER'] except KeyError: pass try: - config['database']['db_path'] = os.environ['DB_PATH'] + configdict['database']['db_path'] = os.environ['DB_PATH'] except KeyError: pass - return config + return configdict # read config in TOML format (https://github.com/toml-lang/toml#toml) From 945a90c7e1ad379b8310382ce7ceb61cf79f1e1d Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 6 Nov 2018 17:50:57 +0100 Subject: [PATCH 12/32] make config.py output directly applicable --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 2b8a6cb..d47bb8e 100755 --- a/config.py +++ b/config.py @@ -60,4 +60,4 @@ except FileNotFoundError: if __name__ == "__main__": for category in config: for key in config[category]: - print(key + " = " + str(config[category][key])) + print(key + "=" + str(config[category][key])) From 5a4763366be2d33ae465c9b3d96ea8877c99e64d Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 6 Nov 2018 18:08:51 +0100 Subject: [PATCH 13/32] if an env var is an empty string, use values from example config --- config.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index d47bb8e..bc7baaf 100755 --- a/config.py +++ b/config.py @@ -13,37 +13,44 @@ def load_env(): configdict = toml.load(defaultconf) try: - configdict['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] + if os.environ['CONSUMER_KEY'] != "": + configdict['twitter']['consumer_key'] = os.environ['CONSUMER_KEY'] except KeyError: pass try: - configdict['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET'] + if os.environ['CONSUMER_SECRET'] != "": + configdict['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET'] except KeyError: pass try: - configdict['web']['host'] = os.environ['HOST'] + if os.environ['HOST'] != "": + configdict['web']['host'] = os.environ['HOST'] except KeyError: pass try: - configdict['web']['port'] = os.environ['PORT'] + if os.environ['PORT'] != "": + configdict['web']['port'] = os.environ['PORT'] except KeyError: pass try: - configdict['web']['contact'] = os.environ['CONTACT'] + if os.environ['CONTACT'] != "": + configdict['web']['contact'] = os.environ['CONTACT'] except KeyError: pass try: - configdict['mail']['mbox_user'] = os.environ['MBOX_USER'] + if os.environ['MBOX_USER'] != "": + configdict['mail']['mbox_user'] = os.environ['MBOX_USER'] except KeyError: pass try: - configdict['database']['db_path'] = os.environ['DB_PATH'] + if os.environ['DB_PATH'] != "": + configdict['database']['db_path'] = os.environ['DB_PATH'] except KeyError: pass From 4c61b1ba9909a76d4dfcb3aa36186e6f7e7e8fca Mon Sep 17 00:00:00 2001 From: b3yond Date: Wed, 7 Nov 2018 01:57:47 +0100 Subject: [PATCH 14/32] setting host to 0.0.0.0 - it never worked with smth else anyway --- frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend.py b/frontend.py index 37144d3..894f6c5 100755 --- a/frontend.py +++ b/frontend.py @@ -260,6 +260,6 @@ bottle.install(SessionPlugin('/')) if __name__ == '__main__': # testing only - bottle.run(host=config["web"]["host"], port=config["web"]["port"]) + bottle.run(host="0.0.0.0", port=config["web"]["port"]) else: application.catchall = False From 8e1234d9b57c9280189edb0355478edc47f379f4 Mon Sep 17 00:00:00 2001 From: b3yond Date: Wed, 7 Nov 2018 09:22:02 +0100 Subject: [PATCH 15/32] removed wrong comment - not only testing, also docker containers use this --- frontend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend.py b/frontend.py index 894f6c5..6b4fe15 100755 --- a/frontend.py +++ b/frontend.py @@ -259,7 +259,6 @@ application = bottle.default_app() bottle.install(SessionPlugin('/')) if __name__ == '__main__': - # testing only bottle.run(host="0.0.0.0", port=config["web"]["port"]) else: application.catchall = False From 268b9748c36e9a4e3beac591e32ad26e1f18f178 Mon Sep 17 00:00:00 2001 From: b3yond Date: Mon, 12 Nov 2018 12:32:28 +0100 Subject: [PATCH 16/32] introduce extra var bc can't write to private attribute --- active_bots/telegrambot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 1c3eae9..eb19be8 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -46,12 +46,12 @@ class TelegramBot(Bot): # TODO: /help message should be set in frontend else: # set report.author to "" to avoid mailbot crash - if update.message.sender.username is None: - update.message.sender.username = "" + sender_name = update.message.sender.username + if sender_name is None: + sender_name = "" - reports.append(Report(update.message.sender.username, self, - update.message.text, None, - update.message.date)) + reports.append(Report(sender_name, self, update.message.text, + None, update.message.date)) return reports def post(self, user, report): From d5823ee1ad054d1212efbebe26fbe17a8dd23d9a Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 28 Dec 2018 14:43:18 +0100 Subject: [PATCH 17/32] removed redundant table declaration --- db.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/db.py b/db.py index 8212560..811d197 100644 --- a/db.py +++ b/db.py @@ -115,13 +115,6 @@ class DB(object): FOREIGN KEY(twitter_accounts_id) REFERENCES twitter_accounts(id) ); - CREATE TABLE IF NOT EXISTS telegram_accounts ( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, - user_id INTEGER, - api_token TEXT, - active INTEGER, - FOREIGN KEY(user_id) REFERENCES user(id) - ); CREATE TABLE IF NOT EXISTS telegram_subscribers ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, user_id INTEGER, From e72d4872c044c9d9bb0415ed54b24fab6e229461 Mon Sep 17 00:00:00 2001 From: b3yond Date: Mon, 31 Dec 2018 15:27:11 +0100 Subject: [PATCH 18/32] more verbose telegram error messages --- active_bots/telegrambot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index eb19be8..2e59da7 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -24,7 +24,9 @@ class TelegramBot(Bot): if update in [303, 404, 420, 500, 502]: return reports if isinstance(update, int): - logger.error("Unknown Telegram error code: " + str(update)) + logger.error("City " + user.uid + + ": Unknown Telegram error code: " + + str(update) + " - " + updates[1]) return reports user.save_seen_tg(update.update_id) if update.message.text.lower() == "/start": From e7e230b2f0894e1b1a1df8ac4337eb7c8addf011 Mon Sep 17 00:00:00 2001 From: b3yond Date: Mon, 31 Dec 2018 15:32:19 +0100 Subject: [PATCH 19/32] when you get crashes bc of your log messages -. --- active_bots/telegrambot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 2e59da7..e17b945 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -24,9 +24,12 @@ class TelegramBot(Bot): if update in [303, 404, 420, 500, 502]: return reports if isinstance(update, int): - logger.error("City " + user.uid + - ": Unknown Telegram error code: " + - str(update) + " - " + updates[1]) + try: + logger.error("City " + user.uid + + ": Unknown Telegram error code: " + + str(update) + " - " + updates[1]) + except TypeError: + logger.error("Unknown Telegram error code: " + str(update)) return reports user.save_seen_tg(update.update_id) if update.message.text.lower() == "/start": From f6c19abad6f272af9700d67681d4c56856c8044e Mon Sep 17 00:00:00 2001 From: b3yond Date: Mon, 31 Dec 2018 15:33:50 +0100 Subject: [PATCH 20/32] fixing the original TypeError --- active_bots/telegrambot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index e17b945..439583b 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -25,9 +25,9 @@ class TelegramBot(Bot): return reports if isinstance(update, int): try: - logger.error("City " + user.uid + + logger.error("City " + str(user.uid) + ": Unknown Telegram error code: " + - str(update) + " - " + updates[1]) + str(update) + " - " + str(updates[1])) except TypeError: logger.error("Unknown Telegram error code: " + str(update)) return reports From a47ad7461964179816a4b5a9863b78d16971a4bd Mon Sep 17 00:00:00 2001 From: git-sid <25916907+git-sid@users.noreply.github.com> Date: Mon, 7 Jan 2019 19:00:51 +0100 Subject: [PATCH 21/32] Replace 3 dots with ellipsis to save space --- active_bots/telegrambot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 439583b..4034743 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -63,7 +63,7 @@ class TelegramBot(Bot): tb = Telegram(user.get_telegram_credentials()) text = report.text if len(text) > 4096: - text = text[:4096 - 4] + u' ...' + text = text[:4096 - 2] + " \N{Horizontal ellipsis}" try: for subscriber_id in user.get_telegram_subscribers(): tb.send_message(subscriber_id, text).wait() From cb2f3cb2e120077f7d9dd0ebdc4aa0b35f72f14d Mon Sep 17 00:00:00 2001 From: git-sid <25916907+git-sid@users.noreply.github.com> Date: Mon, 7 Jan 2019 19:02:07 +0100 Subject: [PATCH 22/32] Fix pep8 non-compliant linebreak --- active_bots/telegrambot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 4034743..9fdbd66 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -47,7 +47,8 @@ class TelegramBot(Bot): elif update.message.text.lower() == "/help": tb.send_message( update.message.sender.id, - "Send reports here to share them with other users. Use /start and /stop to get reports or not.") + "Send reports here to share them with other users. " + "Use /start and /stop to get reports or not.") # TODO: /help message should be set in frontend else: # set report.author to "" to avoid mailbot crash From 2bee67bf843642fb7482c2eec8ef9bb3cfc40dd0 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 7 Jan 2019 14:51:37 -0500 Subject: [PATCH 23/32] Add mission to README. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 560d899..185541d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,16 @@ Ticketfrei is a mastodon/twitter/mail bot to dodge ticket controllers in public transport systems. +## Mission + +Public transportation is meant to provide an easy and time-saving way to move within a region while being affordable for everybody. Unfortunately, this is not yet the case. Ticketfrei's approach is to **enable people to reclaim public transportation.** + +On short term we want to do this by helping users to avoid controllers and fines - on long term by **pressuring public transportation companies to offer their services free of charge**, financed by the public. + +Because with Ticketfrei you're able to use trains and subways for free anyway. Take part and create a new understanding of what public transportation could look like! + +## How It Works + The functionality is simple: It retweets every tweet where it is mentioned. This leads to a community which evolves around it. If you see ticket From a529f4eb2341d509458d755843b5622d8504b29c Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 11:41:20 +0100 Subject: [PATCH 24/32] formatting #70 --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 185541d..680285d 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,18 @@ transport systems. ## Mission -Public transportation is meant to provide an easy and time-saving way to move within a region while being affordable for everybody. Unfortunately, this is not yet the case. Ticketfrei's approach is to **enable people to reclaim public transportation.** +Public transportation is meant to provide an easy and time-saving way to move +within a region while being affordable for everybody. Unfortunately, this is +not yet the case. Ticketfrei's approach is to **enable people to reclaim public +transportation.** -On short term we want to do this by helping users to avoid controllers and fines - on long term by **pressuring public transportation companies to offer their services free of charge**, financed by the public. +On short term we want to do this by helping users to avoid controllers and +fines - on long term by **pressuring public transportation companies to offer +their services free of charge**, financed by the public. -Because with Ticketfrei you're able to use trains and subways for free anyway. Take part and create a new understanding of what public transportation could look like! +Because with Ticketfrei you're able to use trains and subways for free anyway. +Take part and create a new understanding of what public transportation could +look like! ## How It Works From 1c8853341a26dea16dc42d8e087390d91cd63f3d Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 12:15:28 +0100 Subject: [PATCH 25/32] check if account already exists #37 --- frontend.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend.py b/frontend.py index 37144d3..0ea9d1f 100755 --- a/frontend.py +++ b/frontend.py @@ -56,6 +56,9 @@ def register_post(): @get('/confirm//') @view('template/propaganda.tpl') def confirm(city, token): + # check whether city already exists + if db.by_city(city): + return dict(error='Account already exists.') # create db-entry if db.confirm(token, city): # :todo show info "Account creation successful." From 2ce27fc52f845b1c238bb6d6a7724a33059cc4f4 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 13:21:47 +0100 Subject: [PATCH 26/32] nicer error messages --- frontend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend.py b/frontend.py index 0ea9d1f..63143d5 100755 --- a/frontend.py +++ b/frontend.py @@ -58,12 +58,13 @@ def register_post(): def confirm(city, token): # check whether city already exists if db.by_city(city): - return dict(error='Account already exists.') + return dict(error='This Account was already confirmed, please try ' + 'signing in.') # create db-entry if db.confirm(token, city): # :todo show info "Account creation successful." redirect('/settings') - return dict(error='Email confirmation failed.') + return dict(error='Account creation failed. Please try to register again.') @post('/login') From 76b3b574f00bff4b386e97447c7a2e95e5bbaebe Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 13:23:37 +0100 Subject: [PATCH 27/32] replaced attribute with get call --- db.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/db.py b/db.py index 811d197..61100ae 100644 --- a/db.py +++ b/db.py @@ -14,7 +14,6 @@ class DB(object): self.conn = sqlite3.connect(dbfile) self.cur = self.conn.cursor() self.create() - self.secret = self.get_secret() def execute(self, *args, **kwargs): return self.cur.execute(*args, **kwargs) @@ -189,7 +188,7 @@ class DB(object): 'passhash': scrypt_mcf( password.encode('utf-8') ).decode('ascii') - }, self.secret).decode('ascii') + }, self.get_secret()).decode('ascii') def mail_subscription_token(self, email, city): """ @@ -203,17 +202,17 @@ class DB(object): token = jwt.encode({ 'email': email, 'city': city - }, self.secret).decode('ascii') + }, self.get_secret()).decode('ascii') return token def confirm_subscription(self, token): - json = jwt.decode(token, self.secret) + json = jwt.decode(token, self.get_secret()) return json['email'], json['city'] def confirm(self, token, city): from user import User try: - json = jwt.decode(token, self.secret) + json = jwt.decode(token, self.get_secret()) except jwt.DecodeError: return None # invalid token if 'passhash' in json.keys(): From 12a0b1efe5475d2b7140343d05bbb87f9c1c9cdf Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 13:38:47 +0100 Subject: [PATCH 28/32] added call to GET version (commit hash) --- README.md | 2 +- frontend.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 680285d..0a68e78 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ virtualenv -p python3 . Install the dependencies: ```shell -pip install tweepy pytoml Mastodon.py bottle pyjwt pylibscrypt Markdown twx +pip install tweepy pytoml Mastodon.py bottle pyjwt pylibscrypt Markdown twx gitpython ``` Configure the bot: diff --git a/frontend.py b/frontend.py index 37144d3..8f86d1e 100755 --- a/frontend.py +++ b/frontend.py @@ -63,6 +63,13 @@ def confirm(city, token): return dict(error='Email confirmation failed.') +@get('/version') +def version(): + import git + repo = git.Repo(search_parent_directories=True) + return repo.head.object.hexsha + + @post('/login') @view('template/login.tpl') def login_post(): From 4bd99ebb90c1157cce91fdda2f833c2f6d47b276 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 13:44:27 +0100 Subject: [PATCH 29/32] updated the issue template --- .github/ISSUE_TEMPLATE/bug_report.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7c1e5b0..045eb1c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -17,6 +17,9 @@ Steps to reproduce the behavior: 3. Scroll down to '....' 4. See error +**Ticketfrei Version** +See the commit on which Ticketfrei is running at example.org/version. + **Screenshots** If applicable, add screenshots to help explain your problem. From 7507d0392d74fc3c71fb7876dc04f141b36b1013 Mon Sep 17 00:00:00 2001 From: sid <25916907+git-sid@users.noreply.github.com> Date: Fri, 11 Jan 2019 13:48:29 +0100 Subject: [PATCH 30/32] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 6b24afd..2249ac4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ Copyright (c) 2017 Thomas L Copyright (c) 2017 b3yond -Copyright (c) 2018 sid +Copyright (c) 2018 sid Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above From 4b8798ddea9ae453ed8f8c4ffa5f024f1380a9a1 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 14:52:58 +0100 Subject: [PATCH 31/32] fixing shutdown when exim4 is not set up --- active_bots/mailbot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py index 7c8fcb5..984d09f 100644 --- a/active_bots/mailbot.py +++ b/active_bots/mailbot.py @@ -19,7 +19,11 @@ class Mailbot(Bot): def crawl(self, user): reports = [] # todo: adjust to actual mailbox - mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user']) + try: + mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user']) + except FileNotFoundError: + logger.error("No mbox file found.", exc_info=True) + return reports for msg in mails: if get_date_from_header(msg['Date']) > user.get_seen_mail(): if user.get_city().lower() in msg['To'].lower(): From 54489807daed432d90fd06cfa2cf58db44e2e059 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 15:16:37 +0100 Subject: [PATCH 32/32] no need for such a verbose error message. --- active_bots/mailbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py index 984d09f..fbcd02b 100644 --- a/active_bots/mailbot.py +++ b/active_bots/mailbot.py @@ -22,7 +22,7 @@ class Mailbot(Bot): try: mails = mailbox.mbox("/var/mail/" + config['mail']['mbox_user']) except FileNotFoundError: - logger.error("No mbox file found.", exc_info=True) + logger.error("No mbox file found.") return reports for msg in mails: if get_date_from_header(msg['Date']) > user.get_seen_mail():