From 07f15a470a76bfa0a2376cfe0bfb5a526f57c3c2 Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 30 May 2019 22:49:09 +0200 Subject: [PATCH] Handle exceptions --- hashtag-spreader.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hashtag-spreader.py b/hashtag-spreader.py index 495783b..61699d0 100644 --- a/hashtag-spreader.py +++ b/hashtag-spreader.py @@ -1,6 +1,11 @@ import json from mastodon import Mastodon, StreamListener + +def print_status(status): + print("time: " + str(status["created_at"])) + print("from: @" + status["account"]["acct"]) + with open("config.json", 'r') as f: config = json.load(f) @@ -18,11 +23,17 @@ if config: class TootListener(StreamListener): def on_update(self, status): print("") - print(" -- new status in chaos.social -- ") - print(status) + print(" -- new status in " + config["source"]["url"] + " -- ") + print_status(status) + #print(status) print("") - print(" -- search in fem.social -- ") - print(fem_social.search(status.url)) + print(" -- search in " + config["drain"]["url"] + " -- ") + try: + search = fem_social.search(status.url) + for s in search["statuses"]: + print_status(s) + except: + print("failed") tootListener = TootListener()