diff --git a/bot.py b/bot.py index bb84713..5537bb8 100644 --- a/bot.py +++ b/bot.py @@ -49,13 +49,19 @@ class CosmicBot(teambot.Handler): self.load_modules() self.tasks.run() def check_rss(self,state,base_state): - newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]]) - if newtrans: - state["known"].extend(newpost(x) for x in newtrans) - for trans in newtrans: - self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans)) - toot.toot("Transmission received: {transmission.title}\n\n{transmission.link}".format(transmission=trans)) - time.sleep(1) + try: + newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]]) + if newtrans: + state["known"].extend(newpost(x) for x in newtrans) + for trans in newtrans: + self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans)) + toot.toot("Transmission received: {transmission.title}\n\n{transmission.link}".format(transmission=trans)) + time.sleep(1) + except: + print("Error occurred while loading feed, will try again...") + print("Traceback is below:") + traceback.print_exc() + pass return state def on_pubmsg(self,channel,nick,text): self.is_admin = self.event.source.userhost == bot_op diff --git a/toot.py b/toot.py index 0f326fb..1fce9cf 100644 --- a/toot.py +++ b/toot.py @@ -4,20 +4,20 @@ from os import chmod, stat from stat import ST_MODE def getmod(fn): - return stat(fn)[ST_MODE] & 0777 + return stat(fn)[ST_MODE] & 0o777 if not exists("usercred.secret"): if not exists("clientcred.secret"): Mastodon.create_app("cosmicbot toots",api_base_url="https://tilde.zone",to_file="clientcred.secret") - chmod("clientcred.secret",0600) - elif getmod("clientcred.secret")!=0600: - chmod("clientcred.secret",0600) + chmod("clientcred.secret",0o600) + elif getmod("clientcred.secret")!=0o600: + chmod("clientcred.secret",0o600) tmp = Mastodon(client_id="clientcred.secret",api_base_url="https://tilde.zone") with open("details.secret") as f: - tmp.log_in(f.readline().strip(),f.readline.strip(),to_file="usercred.secret") - chmod("usercred.secret",0600) -elif getmod("usercred.secret")!=0600: - chmod("usercred.secret",0600) + tmp.log_in(f.readline().strip(),f.readline().strip(),to_file="usercred.secret") + chmod("usercred.secret",0o600) +elif getmod("usercred.secret")!=0o600: + chmod("usercred.secret",0o600) m = Mastodon(access_token='usercred.secret',api_base_url="https://tilde.zone")