Exemplo n.º 1
0
def index():
    if not session.get("email"):
        return render_template("index_not_logged_in.html")

    update_recommendation_matrix()
    num_recommendations = 5
    recommendations = get_recommended_friends(
        num_recommendations, recommendation_matrix)
    recommendations = db.get_user_data(recommendations)

    friends = db.get_all_friends(session["email"])
    friends = db.get_user_data(friends)

    return render_template("index_logged_in.html", movies=movies, recommendations=recommendations, friends=friends)
Exemplo n.º 2
0
def get_user_info():
    req = json.loads(request.data)
    user = json.loads(req['user'])
    return get_user_data(user)
Exemplo n.º 3
0
def notify():
	Id = request.get_json()['Id']
	if Id != None:
		push(get_user_data(Id)["Subscription_info"])
	return Response(status=200)
Exemplo n.º 4
0
def sched():
	Id = session.get('Id')
	if Id == None:
		return redirect('/')
	data = get_user_data(Id)
	return render_template('note.html' , name=data['username'])
Exemplo n.º 5
0
def dashboard():
	Id = session.get('Id')
	if Id == None:
		return redirect('/')
	data = get_user_data(Id)
	return render_template('home.html' , name=data['username'] , temprature=data['Temprature'] , Water=data['Water_Level'] , SM=data['Soil_Moisture'] , HM=data['Humidity'])
Exemplo n.º 6
0
Arquivo: main.py Projeto: ogroleg/mbot
def on_message(bot, update):
    chat_id = update.message.chat_id
    text = update.message.text

    user_data = db.get_user_data(chat_id)
    state = user_data.get('state', None)

    if state is None:
        state = c.DEFAULT_STATE
        db.set_user_state(chat_id, state)

    state = state.decode('utf-8')

    if state == 'sheet_registration':
        worksheets = helpers.get_worksheets(text)

        if worksheets is not None:
            db.set_user_field(chat_id, 'document', text)
            db.set_user_state(chat_id, 'worksheet_selection')

            keyboard = [[InlineKeyboardButton(ws.title, callback_data=ws.id)]
                        for ws in worksheets]
            keyboard.append([
                InlineKeyboardButton(c.TEXTS['CREATE_NEW_WORKSHEET'],
                                     callback_data='None')
            ])

            reply_markup = InlineKeyboardMarkup(keyboard)

            return update.message.reply_text(c.TEXTS['WORKSHEET_SELECTION'],
                                             reply_markup=reply_markup)
        else:
            return update.message.reply_text(
                c.TEXTS['DOCUMENT_VALIDATION_ERROR'])
    elif state == 'worksheet_creation':
        ws = helpers.create_worksheet(user_data[b'document'], text)

        db.set_user_field(chat_id, 'worksheet', ws.id)
        db.set_user_state(chat_id, 'ready')

        return registration_completed(chat_id=chat_id, bot=bot)
    elif state == 'category_add':
        db.set_user_state(chat_id, 'ready')
        db.add_user_category(chat_id, text)
        return list_categories(chat_id, bot=bot)
    elif state == 'ready':
        # ready to receive new spendings
        data = helpers.parse_new_spendings(text)

        if not data:
            return update.message.reply_text(
                c.TEXTS['ERROR_PARSING_SPENDINGS'])

        message = update.message.reply_text(
            c.TEXTS['STORING_SPENDINGS_IN_PROGRESS'])
        message_id = message.message_id

        db.store_user_spendings(
            chat_id, message_id,
            data)  # background processing starts after this
        return
Exemplo n.º 7
0
Arquivo: main.py Projeto: ogroleg/mbot
def on_callback_query(bot, update):
    callback_query = update.callback_query
    query = callback_query.data

    chat_id = callback_query.from_user.id

    user_data = db.get_user_data(chat_id)
    state = user_data[b'state'].decode('utf-8')

    document = user_data[b'document']
    print(query)
    print(state)

    if query == 'empty':
        return

    if state == 'worksheet_selection':
        if query == 'None':
            db.set_user_state(chat_id, 'worksheet_creation')
            return callback_query.edit_message_text(
                text=c.TEXTS['WORKSHEET_CREATION'], reply_markup=None)

        if helpers.validate_worksheet(document.decode('utf-8'), query):
            db.set_user_field(chat_id, 'worksheet', query)

            if not helpers.is_worksheet_empty(document.decode('utf-8'), query):
                db.set_user_state(chat_id, 'configuring_worksheet')

                keyboard = [[
                    InlineKeyboardButton(c.TEXTS['REWRITE_WORKSHEET'],
                                         callback_data='clear')
                ],
                            [
                                InlineKeyboardButton(
                                    c.TEXTS['APPEND_WORKSHEET'],
                                    callback_data='append')
                            ]]

                reply_markup = InlineKeyboardMarkup(keyboard)

                return callback_query.edit_message_text(
                    text=c.TEXTS['WORKSHEET_CONFIGURATION'],
                    reply_markup=reply_markup)

            db.set_user_state(chat_id, 'ready')
            return registration_completed(chat_id=chat_id,
                                          bot=bot,
                                          callback_query=callback_query)
        else:
            return callback_query.edit_message_text(text='Error')
    elif state == 'configuring_worksheet':
        if query == 'clear':
            helpers.clear_worksheet(document.decode('utf-8'),
                                    user_data[b'worksheet'])

        return registration_completed(chat_id=chat_id,
                                      bot=bot,
                                      callback_query=callback_query)
    elif query.startswith('categories_'):
        query = query[11:]

        if query == 'enable':
            db.set_user_field(chat_id, 'categories_enabled', True)
            return list_categories(chat_id, callback_query=callback_query)
        elif query == 'disable':
            db.set_user_field(chat_id, 'categories_enabled', False)
            return enable_categories_button(callback_query=callback_query)
        elif query == 'add':
            db.set_user_state(chat_id, 'category_add')
            return callback_query.edit_message_text(
                text=c.TEXTS['CATEGORIES_INPUT_NEW'], reply_markup=None)
        elif query.startswith('del_'):
            category_to_remove = query[4:]
            db.remove_user_category(chat_id, category_to_remove)
            return list_categories(chat_id, callback_query=callback_query)