fixing more telegram bugs

This commit is contained in:
b3yond 2018-09-09 17:51:07 +02:00
parent a0bd5e69e1
commit 6cac81e444
3 changed files with 9 additions and 4 deletions

View file

@ -11,7 +11,10 @@ class TelegramBot(Bot):
def crawl(self, user):
tb = Telegram(user.get_telegram_credentials())
seen_tg = user.get_seen_tg()
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)

4
db.py
View file

@ -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 (?,?)",

View file

@ -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