Beispiel #1
0
async def schedule_trigger():
    while True:
        now = datetime.now()
        now = now.replace(second=0, microsecond=0)
        for story in Story.select().where(Story.scheduled_datetime == now,
                                          Story.prod_message_id == None):
            img_links = json.loads(story.img_links)

            if len(img_links) == 1:
                response = await bot.send_photo(MEMOTRON_CHANNEL,
                                                photo=img_links[0],
                                                caption=story.title)

            elif len(img_links) > 1:
                medias = [InputMediaPhoto(url) for url in img_links]
                if len(medias) > 10:  # TG limit
                    return

                response = await bot.send_media_group(MEMOTRON_CHANNEL, medias)
                response = response[0]
            else:
                response = await bot.send_message(MEMOTRON_CHANNEL,
                                                  text=story.text)
            logger.info(response)
            story.prod_message_id = response['message_id']
            story.save()

            await sleep(1)
        await sleep(1)
Beispiel #2
0
async def watch_new_stories() -> None:
    while True:
        unpublished_stories = Story.select().where(
            Story.admin_message_id.is_null(), Story.text == "")

        for story in unpublished_stories:
            try:
                await schedule_new_post(story)
            except Exception as e:
                logger.exception(e)
            await sleep(1)
        await sleep(1)
Beispiel #3
0
async def update_keyboards() -> None:
    """Updates message keyboards in admin channel"""
    while True:
        for story in Story.select().\
                           where(Story.scheduled_datetime.is_null()).\
                           order_by(Story.post_datetime.desc()):
            keyboard = get_story_keyboard(story)
            try:
                await bot.edit_message_reply_markup(
                    ADMIN_CHANNEL,
                    message_id=story.admin_message_id,
                    reply_markup=keyboard)
            except (MessageToEditNotFound, MessageNotModified) as e:
                logger.debug(e)
            await sleep(3)
Beispiel #4
0
def display_stories():
    stories = Story.select().order_by(Story.id)
    return render_template('list.html', stories=stories)
Beispiel #5
0
def delete_story(story_id):
    story = Story.select().where(Story.id == story_id).get()
    story.delete_instance()
    story.save()
    return redirect(url_for('display_stories'))
def show_stories():
    stories = Story.select()
    return render_template('list.html', stories=stories)
Beispiel #7
0
def story(id):
    if Story.select().where(Story.id == id).exists():
        user_story = Story.get(Story.id == id)
    else:
        user_story = None
    return render_template("form.html", user_story=user_story)
Beispiel #8
0
def list():
    stories = Story.select().order_by(Story.id.asc())
    return render_template('list.html', stories=stories)