def mongo_db_checker(connector, data):
	try:
		database.get_info(connector, data)[0]
		return True
	except Exception as e:
		print(e)
		return False
def auth(account, password):
    print(account)
    info = database.get_info('user', 'password', account)
    print(info)
    if password:
        if password == info:
            return database.get_info('user', 'id', account)
        else:
            return 'err2'
    else:
        return 'err1'
Exemple #3
0
def search():
    query = request.args.get('q', '')
    if 'HTTP_X_FORWARDED_FOR' in request.environ:
        submit_metric('/search', query,
                      request.environ['HTTP_X_FORWARDED_FOR'])
    info = get_info(query)
    return render_template('info.html', info=info, query=query)
Exemple #4
0
def check_handler(user_key):
    if module.checker_in_mongo(config.users, {'user_key': user_key}):
        data = request.get_json()
        if 'item_id' in data:
            if module.checker_in_mongo(config.todoItems,
                                       {'_id': data['item_id']}):
                item_info = database.get_info(config.todoItems,
                                              {'_id': data['item_id']})[0]
                if item_info['user_key'] == user_key:
                    item_info['check'] = not (item_info['check'])
                    database.update_info(config.todoItems,
                                         {'_id': data['item_id']},
                                         {'check': item_info['check']})
                    return jsonify({'ok': True, 'item': {item_info}})
                else:
                    return jsonify({
                        'ok': False,
                        'error': strings.INVALID_ITEM_ID
                    })
            else:
                return jsonify({'ok': False, 'error': strings.INVALID_ITEM_ID})
        else:
            return jsonify({'ok': False, 'error': strings.INVALID_DATA})
    else:
        return jsonify({'ok': False, 'error': strings.INVALID_USER_KEY})
Exemple #5
0
def users_page():
    if request.method == 'GET':
        users = db.get_info("users")
        return render_template("users.html", users=users)
    elif request.method == 'POST':
        if request.form.get("action") == "edit":
            data = {
                "user_id": request.form.get("user_id"),
                "name": request.form.get('name'),
                "surname": request.form.get('surname')
            }
            db.edit_user(data)
            print(data)
        elif request.form.get("action") == "delete":
            db.delete_user(request.form.get("user_id"))
        users = db.get_info("users")
        return render_template("users.html", users=users)
Exemple #6
0
def getMe_handler(user_key):
    if module.checker_in_mongo(config.users, {'user_key': user_key}):
        result = {'ok': True}
        result['items'] = [
            *database.get_info(config.todoItems, {'user_key': user_key})
        ]
        return jsonify(result)
    else:
        return jsonify({'ok': False, 'error': strings.INVALID_USER_KEY})
Exemple #7
0
def add():
    # print("add")
    # print(request.method)
    if request.method =="GET":
        return render_template("add.html")
    elif request.method == "POST":
        pname = request.form["pname"]
        problem = request.form["problem"]
        description = request.form["description"]
        database.add_problem(pname , problem , description)
        info = database.get_info()
        # print(pname, problem, description)       
        return redirect(url_for('problems', info = info))
def start_handler(message):
    print(message.text)
    if not module.mongo_db_checker(config.users,
                                   {'user_id': message.from_user.id}):
        database.insert_into(config.users, module.new_user(message))
    if len(message.text.split()) >= 2:
        if module.mongo_db_checker(config.messages,
                                   {'code': message.text.split()[1]}):
            message_data = database.get_info(
                config.messages, {'code': message.text.split()[1]})[0]
            try:
                if message_data['content_type'] == 'text':
                    bot.send_message(message.chat.id, message_data['text'])
                elif message_data['content_type'] == 'photo':
                    bot.send_photo(message.chat.id, message_data['photo'],
                                   message_data['caption'])
                elif message_data['content_type'] == 'audio':
                    bot.send_audio(message.chat.id, message_data['audio'],
                                   message_data['caption'])
                elif message_data['content_type'] in [
                        'document' in 'video_note'
                ]:
                    bot.send_document(message.chat.id,
                                      message_data['document'],
                                      message_data['caption'])
                elif message_data['content_type'] == 'sticker':
                    bot.send_sticker(message.chat.id, message_data['sticker'])
                elif message_data['content_type'] == 'video':
                    bot.send_video(message.chat.id, message_data['video'],
                                   message_data['caption'])
                elif message_data['content_type'] == 'voice':
                    bot.send_voice(message.chat.id, message_data['voice'],
                                   message_data['voice'])
                elif message_data['content_type'] == 'location':
                    bot.send_location(message.chat.id,
                                      message_data['location']['lat'],
                                      message_data['location']['lon'])
                elif message_data['content_type'] == 'contact':
                    bot.send_contact(message.chat.id,
                                     message_data['contact']['phone_number'],
                                     message_data['contact']['first_name'],
                                     message_data['contact']['last_name'])
            except Exception as e:
                print(e)
                config.app.forward_messages(
                    '@' + bot_username, message_data['channel']['chat_id'],
                    message_data['channel']['message_id'])
                start_handler(message)
            return
    bot.send_message(message.chat.id, strings.WELCOME, parse_mode='html')
Exemple #9
0
def settings(message):
    Home = types.ReplyKeyboardMarkup()
    home = types.InlineKeyboardButton('Home 🏠')
    solo = types.InlineKeyboardButton('Solo game 🧐')
    multiplayer = types.InlineKeyboardButton('Play with friend 👨‍👦‍👦')
    Home.add(home)
    Home.add(solo, multiplayer)
    user = db.get_info(message.from_user.id)
    send = bot.send_message(
        message.chat.id,
        'Your settings ⚙️: \n\nId 👊: {id}\nUsername 🤙: {un}\nName 👨‍🦰: {name}\n\n\nMoney 💶: {money}\n\n\nTotal win 🏆: {win}\nTotal number of games played 🎮: {tg} \n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}\n\n\n If you wont back to home click on button below. ⬇️⬇️⬇️'
        .format(id=message.from_user.id,
                un=message.from_user.username if
                message.from_user.username != None else 'you haven`t username',
                name=message.from_user.first_name,
                money=user[3],
                win=user[4],
                tg=user[5],
                srn=db.get_product(message.from_user.id, True, False, False),
                s_t_n=db.get_product(message.from_user.id, False, False, True),
                sen=db.get_product(message.from_user.id, False, True, False)),
        reply_markup=Home)
    bot.register_next_step_handler(send, update_message)
Exemple #10
0
def checker_in_mongo(connector, data):
	try:
		database.get_info(connector, data)[0]
		return True
	except:
		return False
Exemple #11
0
def db():
    query = request.args.get('name', '')
    return str(get_info(query))
            if j in most_common:
                most_common[j] += 1
            else:
                most_common[j] = 1
    sorted_list = sorted(most_common.items(),
                         key=operator.itemgetter(1),
                         reverse=True)
    return sorted_list[:5], [sorted_list[i][0] for i in range(5)]


while True:
    print("Waiting For New Data")
    msg = consumer.poll(timeout_ms=1000, max_records=1)
    if not msg:
        continue
    print('receive', msg)
    value = list(msg.values())[0]
    user_id = value[0].value
    _, data = similar_user_recs(user_id)
    name = []
    for id in data:
        name.append(get_info('item', 'name', id))
    future = producer.send('cf_item', dumps(name))
    try:
        record_metadata = future.get(timeout=10)
    except KafkaError:
        # Decide what to do if produce request failed...
        log.exception()
        pass
    print('predict sent!', record_metadata.offset)
Exemple #13
0
def problems():
    info=database.get_info()
    return render_template("problems.html",info =info)