From 6cac81e44440980582b8f721137a7439f8c450a1 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 9 Sep 2018 17:51:07 +0200 Subject: [PATCH] fixing more telegram bugs --- active_bots/telegrambot.py | 7 +++++-- db.py | 4 +++- user.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 637b332..65320fb 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -11,7 +11,10 @@ class TelegramBot(Bot): def crawl(self, user): tb = Telegram(user.get_telegram_credentials()) seen_tg = user.get_seen_tg() - updates = tb.get_updates(offset=seen_tg+1).wait() + try: + updates = tb.get_updates(offset=seen_tg+1).wait() + except TypeError: + updates = tb.get_updates().wait() reports = [] for update in updates: try: @@ -45,4 +48,4 @@ class TelegramBot(Bot): tb.send_message(subscriber_id, text).wait() except Exception: logger.error('Error telegramming: ' + user.get_city() + ': ' - + report.id, exc_info=True) + + str(report.id), exc_info=True) diff --git a/db.py b/db.py index 3fa09db..a224a0f 100644 --- a/db.py +++ b/db.py @@ -79,7 +79,7 @@ class DB(object): id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, user_id INTEGER, tg_id INTEGER, - FOREIGN KEY(user_id) REFERENCES user(id), + FOREIGN KEY(user_id) REFERENCES user(id) ); CREATE TABLE IF NOT EXISTS twitter_request_tokens ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, @@ -264,6 +264,8 @@ u\d\d? (uid, json['email'])) self.execute("""INSERT INTO telegram_accounts (user_id, apikey, active) VALUES(?, ?, ?);""", (uid, "", 1)) + self.execute("INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?,?);", + (uid, 0)) self.commit() user = User(uid) self.execute("INSERT INTO seen_mail (user_id, mail_date) VALUES (?,?)", diff --git a/user.py b/user.py index e87c372..92e8657 100644 --- a/user.py +++ b/user.py @@ -104,7 +104,7 @@ schlitz def get_telegram_subscribers(self): db.execute("""SELECT subscriber_id FROM telegram_subscribers - WHERE user_id = ? AND active = 1;""", + WHERE user_id = ?;""", (self.uid,)) rows = db.cur.fetchall() return rows