Beispiel #1
0
def f_game():
    if session.get("user"):
        inf = request.args.get("inf", "", type=str)
        print "123"
        if get_post(inf):
            stup = list(get_post(inf))
            stup[8] = str(stup[8])
            stup[17] = str(stup[17])
            if "Publisher" in stup[17]:
                d = stup[17].index("Publisher")
                stup[17] = stup[17][:d]
            return json.dumps(stup)
        return "0"
    return redirect(url_for("f_home"))
Beispiel #2
0
def f_game():
    if session.get("user"):
        inf = request.args.get("inf", "", type=str)
        print "123"
        if get_post(inf):
            stup = list(get_post(inf))
            stup[8] = str(stup[8])
            stup[17] = str(stup[17])
            if "Publisher" in stup[17]:
                d = stup[17].index("Publisher")
                stup[17] = stup[17][:d]
            return json.dumps(stup)
        return "0"
    return redirect(url_for("f_home"))
Beispiel #3
0
def add_reaction_callback(query, data, chat, message):
    db.add_user(query.sender.id)
    post = db.get_post(message.id, chat.id)
    sender = query.sender
    reaction = db.get_reaction(post.post_id, sender.id)
    btns = botogram.Buttons()

    # se viene cliccata la stessa reazione la toglie, altrimenti la cambia
    if reaction:
        if reaction.reaction_type == 'upvote':
            if data == 'upvote':
                db.remove_reaction(post.post_id, sender.id)
            elif data == 'downvote':
                db.set_reaction(post.post_id, sender.id, 'downvote')
        elif reaction.reaction_type == 'downvote':
            if data == 'downvote':
                db.remove_reaction(post.post_id, sender.id)
            elif data == 'upvote':
                db.set_reaction(post.post_id, sender.id, 'upvote')
    # aggiunge una nuova reazione
    else:
        db.add_reaction(post.post_id, sender.id, data)

    # aggiorna i numeri nei bottoni
    post_reactions = db.get_reactions_count(post.post_id)
    btns[0].callback(f"👍{post_reactions['upvotes']}", "add_reaction_callback",
                     "upvote")
    btns[0].callback(f"👎{post_reactions['downvotes']}",
                     "add_reaction_callback", "downvote")

    message.edit_attach(btns)
Beispiel #4
0
def get_post(post_id):
    post_info = database.get_post(post_id)
    product_info = database.get_product(post_id)
    image_info = database.get_image(post_id)
    result = json.loads(post_info)
    result[0]["products"] = product_info
    result[0]["images"] = image_info
    print(str(result[0]))
    return json.dumps(result[0])
Beispiel #5
0
async def edit_post(request, id):
    if len(request.form) == 0:
        post = db.get_post(id)
        print('*' * 80)
        print(post['content'])
        return jinja.render('edit.html', request, post=post)
    post = {
        'id': id,
        'title': request.form.get('title'),
        'content': markdown(request.form.get('content')),
        'create_at': datetime.now()
    }
    db.update_post(post)
    return redirect(app.url_for('post', id=post['id']))
def answer(bot, data, text):
    text_arr = text.split(" ")
    question_number = str(text_arr[0])
    question = database.get_post(question_number)
    try:
        question_token = question[2]
    except:
        message = "Данного вопроса не существует, проверьте введенный номер"
        bot.send_text(chat_id=data["chat"]["chatId"], text=message)
        return
    if question_token == bot.token:
        answer = ""
        for i in range(1, len(text_arr)):
            answer = answer + text_arr[i] + " "
        message = "Ответ на вопрос " + question_number + " успешно отправлен"
        bot.send_text(chat_id=data["chat"]["chatId"], text=message)
        bot.send_text(chat_id=question[3], text=answer)
    else:
        message = "Данный вопрос не принадлежит вашему боту, проверьте введенный номер"
        bot.send_text(chat_id=data["chat"]["chatId"], text=message)
Beispiel #7
0
async def post(request, id):
    post = db.get_post(id)
    comments = db.get_comment(id)
    if post is not None:
        return jinja.render('post.html', request, post=post, comments=comments)
    return response.text('no post')
def get_db():
    post = database.get_post()
    return post