Merge remote-tracking branch 'origin/multi-deployment' into multi-deployment
This commit is contained in:
commit
a0bd5e69e1
|
@ -10,7 +10,8 @@ logger = logging.getLogger(__name__)
|
||||||
class TelegramBot(Bot):
|
class TelegramBot(Bot):
|
||||||
def crawl(self, user):
|
def crawl(self, user):
|
||||||
tb = Telegram(user.get_telegram_credentials())
|
tb = Telegram(user.get_telegram_credentials())
|
||||||
updates = tb.get_updates().wait()
|
seen_tg = user.get_seen_tg()
|
||||||
|
updates = tb.get_updates(offset=seen_tg+1).wait()
|
||||||
reports = []
|
reports = []
|
||||||
for update in updates:
|
for update in updates:
|
||||||
try:
|
try:
|
||||||
|
@ -28,6 +29,7 @@ class TelegramBot(Bot):
|
||||||
else:
|
else:
|
||||||
reports.append(Report(update.message.sender.username, self,
|
reports.append(Report(update.message.sender.username, self,
|
||||||
update.message.text, None, update.message.date))
|
update.message.text, None, update.message.date))
|
||||||
|
user.save_seen_tg(update.message.id)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print(updates[0], updates[1]) # Telegram API returns an Error
|
print(updates[0], updates[1]) # Telegram API returns an Error
|
||||||
return reports
|
return reports
|
||||||
|
|
6
db.py
6
db.py
|
@ -75,6 +75,12 @@ class DB(object):
|
||||||
FOREIGN KEY(mastodon_accounts_id)
|
FOREIGN KEY(mastodon_accounts_id)
|
||||||
REFERENCES mastodon_accounts(id)
|
REFERENCES mastodon_accounts(id)
|
||||||
);
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS seen_telegrams (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
|
user_id INTEGER,
|
||||||
|
tg_id INTEGER,
|
||||||
|
FOREIGN KEY(user_id) REFERENCES user(id),
|
||||||
|
);
|
||||||
CREATE TABLE IF NOT EXISTS twitter_request_tokens (
|
CREATE TABLE IF NOT EXISTS twitter_request_tokens (
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
user_id INTEGER,
|
user_id INTEGER,
|
||||||
|
|
10
user.py
10
user.py
|
@ -184,6 +184,16 @@ schlitz
|
||||||
(tweet_id, self.uid))
|
(tweet_id, self.uid))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
def get_seen_tg(self):
|
||||||
|
db.execute("SELECT tg_id FROM seen_telegrams WHERE user_id = ?;",
|
||||||
|
(self.uid,))
|
||||||
|
return db.cur.fetchone()
|
||||||
|
|
||||||
|
def save_seen_tg(self, tg_id):
|
||||||
|
db.execute("UPDATE seen_telegrams SET tg_id = ? WHERE user_id = ?;",
|
||||||
|
(tg_id, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_mailinglist(self):
|
def get_mailinglist(self):
|
||||||
db.execute("SELECT email FROM mailinglist WHERE user_id = ?;", (self.uid, ))
|
db.execute("SELECT email FROM mailinglist WHERE user_id = ?;", (self.uid, ))
|
||||||
return db.cur.fetchall()
|
return db.cur.fetchall()
|
||||||
|
|
Loading…
Reference in a new issue