aboutsummaryrefslogtreecommitdiff
path: root/timelinebot.py
diff options
context:
space:
mode:
authorTianhao Wang <tianhao.wang2@mailbox.tu-dresden.de>2023-10-14 00:36:31 +0200
committerTianhao Wang <tianhao.wang2@mailbox.tu-dresden.de>2023-10-14 00:36:31 +0200
commit34b585ec2709fffaebf8fd2cfc7dd24dfd953d87 (patch)
treeedb1e815329e604d74716917daf011c5e0941ae1 /timelinebot.py
parent4e8d0ec6853f9cbb97eba787a87f1a03f5f95c95 (diff)
fix bug
Diffstat (limited to 'timelinebot.py')
-rwxr-xr-xtimelinebot.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/timelinebot.py b/timelinebot.py
index 8cf6635..98fe1a9 100755
--- a/timelinebot.py
+++ b/timelinebot.py
@@ -13,34 +13,35 @@ class TLBot():
self.config = cfg
def init_app(self):
- self.session = Mastodon.create_app(self.config.APPNAME, api_base_url=self.config.BASEURL, to_file=self.config.CLIENTID)
+ try:
+ Mastodon.create_app(self.config.APPNAME, api_base_url=self.config.BASEURL, to_file=self.config.CLIENTID)
+ self.session = Mastodon(client_id=self.config.CLIENTID, access_token=self.config.TOKEN, feature_set="pleroma")
+ except Exception as e:
+ print("[booting] app init failed")
def init_session(self):
if not os.path.isfile(self.config.CLIENTID):
- print("[booting] client data doesn't exist..creating...")
- self.session = self.init_app()
+ print("[booting] first time? creating new app..")
+ self.init_app()
+ self.login()
+ return
else:
self.session = Mastodon(client_id=self.config.CLIENTID, access_token=self.config.TOKEN, feature_set="pleroma")
try:
self.session.account_verify_credentials()
+ print("[auth] credentials valid")
except:
- print("invalid credentials, trying to log in with pw")
- try:
- self.login()
- except Exception as e:
- print("can't log in, abort")
- print(e)
- exit()
+ print("[auth] invalid credentials, trying to log in with pw")
+ self.login()
def login(self):
- print("trying manual login")
+ print("[auth] trying manual login")
if self.config.UNAME == "" or self.config.PW == "":
(self.config.UNAME, self.config.PW) = cfg.get_secrets_from_input()
try:
self.session.log_in(username=self.config.UNAME,password=self.config.PW, to_file=self.config.TOKEN)
except Exception as e:
- print("log in failed, check your credentials")
- print(e)
+ print("[auth] log in failed: ", e)
exit()
def get_sanitized_timeline_json(self):
@@ -69,7 +70,9 @@ class TLBot():
if __name__ == "__main__":
bot = TLBot(cfg)
bot.init_session()
+ print("[info] fetching timeline")
sl = bot.get_sanitized_timeline_json()
+ print("[info] timeline fetched: ", len(sl), " statuses")
file = cfg.OUTPUT_JSON_FILE
with open(file, 'w', encoding='utf8') as json_file:
json.dump(sl, json_file, ensure_ascii=False)