Exemple #1
0
 def post_exists(url):
     exists = Post.select().where(Post.url == url).exists()
     if exists:
         logger.info(f'Post exists: {url}')
     else:
         logger.info(f'Found new post: {url}')
     return exists
Exemple #2
0
def cleaner():
    logger.info('Start cleaner!')
    published_posts = Post.select().where(Post.published_at != None)
    for post in published_posts:
        os.remove(post.file_path)
        logger.info(f'File {post.file_path} was removed')
        Post.update(file_deleted=True).where(Post.id == post.id).execute()
Exemple #3
0
def publish():
    logger.info('Start to publish')
    bot = init_bot()

    unpublished_posts = Post.select().where(
        Post.published_at == None).order_by(Post.created_at.desc()).limit(1)

    for post in unpublished_posts:
        logger.info(f'Publish {post.title}')
        msg = prepare_message(post)
        bot.send_message(chat_id=settings.tg_chat_id,
                         text=msg,
                         parse_mode='Markdown')
        bot.send_audio(chat_id=settings.tg_chat_id,
                       audio=open(post.file_path, 'rb'),
                       timeout=300,
                       title=post.title)
        Post.update(published_at=datetime.now(timezone.utc)).where(
            Post.id == post.id).execute()
        logger.info(f'Post {post.title} successfully published!')