def get_favourites(user=None):
    if not user and logged_in():
        user = session['username']

    favourites = database.get_favourites(user)

    if not favourites:
        return None

    output = []
    for f in favourites:
        output.append({
            'file':
            url_for('static',
                    filename=f['author'] + '/' + f['date_uploaded'] + '.png'),
            'username':
            f['username'],
            'title':
            database.get_picture(f['author'], f['date_uploaded'])['title'],
            'author':
            f['author'],
            'date_uploaded':
            f['date_uploaded'],
            'date_uploaded_formatted':
            get_formatted_time(get_epoch_time(f['date_uploaded'])),
            'date_added':
            f['date_added'],
            'date_added_formatted':
            get_formatted_time(get_epoch_time(f['date_added']))
        })

    return output
示例#2
0
def button_processing(bot, event):
    data = event.data
    if data["message"]["chat"]["type"] == "private":
        func_arr = data["callbackData"].split("_")
        picture = database.get_picture(func_arr[1])
        inlineKeyboardMarkup = json.dumps(
            [[{
                "text":
                "Опубликовать",
                "callbackData":
                "func_post_" + str(picture[0]) + "_" + str(picture[1])
            }],
             [{
                 "text":
                 "Не публиковать",
                 "callbackData":
                 "func_delete_" + str(picture[0]) + "_" + str(picture[1])
             }]])
        bot.send_file(chat_id=config.admin_channel,
                      file_id=picture[6],
                      inline_keyboard_markup=inlineKeyboardMarkup)
        text = "Фотография успешно предложена и отправлена на модерацию"
        bot.send_text(chat_id=data["message"]["chat"]["chatId"], text=text)
    else:
        if data["message"]["chat"]["chatId"] == "*****@*****.**":
            if "func_post" in data["callbackData"]:
                id_post = data["callbackData"][10:]
                post_process(bot, id_post, data, "post")
            elif "func_delete" in data["callbackData"]:
                text = data["callbackData"][12:]
                post_process(bot, text, data, "delete")
示例#3
0
def post_process(bot, text, data, proc_type):
    id_post = text[0]
    picture = database.get_picture(id_post)
    print(picture)
    if picture[7] == "no_posted":
        if proc_type == "delete":
            admin_text = "Пост успешно удален"
            bot.send_text(chat_id=config.admin_channel, text=admin_text)
            return
        text = picture[1]
        admin_text = "Пост успешно опубликован"
        bot.send_file(chat_id=config.channel, file_id=picture[6])
    else:
        admin_text = "Данный пост уже обработан"
    bot.send_text(chat_id=config.admin_channel, text=admin_text)
    database.update_status(id_post)
def get_picture(user, date):
    picture = database.get_picture(user, date)
    if not picture:
        return None

    file = url_for('static',
                   filename='uploads/' + picture['author'] + '/' +
                   picture['date_uploaded'] + '.png')
    return {
        'file':
        file,
        'author':
        picture['author'],
        'date_uploaded':
        picture['date_uploaded'],
        'date_uploaded_formatted':
        get_formatted_time(get_epoch_time(picture['date_uploaded'])),
        'title':
        picture['title'],
        'description':
        picture['description'],
    }
示例#5
0
        "➡️Отправить в Бессмертный полк",
        "callbackData":
        "post_" + str(picture[0]),
        "style":
        "primary"
    }]])
    with open("img/result.png", "rb") as result_file:
        try:
            img_result = bot.send_file(
                chat_id=picture[1],
                file=result_file,
                inline_keyboard_markup=inlineKeyboardMarkup).json()
        except:
            database.update_photo_result(picture[0], "Картинка поломана")
            return
    message = """Большое спасибо за участие в акции! Поделитесь этой фотографией со своими друзьями и в социальных сетях. Пусть в нашем полку окажется как можно больше героев!\n\nНажав на кнопку, вы соглашаетесь с публикацией вашей фотографии в канале «Шествие Бессмертного полка»"""
    bot.send_text(chat_id=picture[1], text=message)
    print(img_result)
    database.update_photo_result(picture[0], img_result["fileId"])


if __name__ == '__main__':
    bot = Bot(token=config.TOKEN)
    while True:
        try:
            picture = database.get_picture()
            if picture:
                render(bot, picture)
        except:
            time.sleep(2)