def public_posts(self):
now = datetime.now()
# ???????? 30 ????????? ??????? ?? rss ?????? ? ??????? ?? ??, ? ??????? message_id=0
posts_from_db = self.db.get_post_without_message_id()
today_news = [i for i in self.src.news if (
now - datetime.fromtimestamp(i.date)).days < 1]
# ????? ?????????? ???? ???????
for_publishing = list(set(today_news) & set(posts_from_db))
for_publishing = sorted(for_publishing, key=lambda news: news.date)
# for_publishing = sorted(today_news, key=lambda news: news.date)
# ??????? ??????? ?????????
for post in tqdm(for_publishing, desc="Posting news"):
header = base64.b64decode(post.text).decode('utf8')
header = ''.join(c for c in header if c not in set(punctuation + '—«»'))
header = '#' + '_'.join(header.lower().split())
text = '%s %s' % (header,
self.bit_ly.short_link(base64.b64decode(post.link).decode('utf8')))
a = self.send_message(
chat_id=self.chat_id, text=text) # , parse_mode=telegram.ParseMode.HTML)
message_id = a.message_id
chat_id = a['chat']['id']
self.db.update(post.link, chat_id, message_id)
logging.info(u'Public: %s;%s;' %
(str(post), message_id))
time.sleep(self.delay_between_messages)
评论列表
文章目录