def exists(user): response = myUsers.find_one({"id": user.id}, {"id": 1}) logger.info("find_one user: " + str(response)) if (response != None): return True else: return False
def newUser(info): user = User(info.id, info.first_name, info.username) if (exists(user)): logger.info("User exists") else: createUserDB(user)
def createExpense(userid, text): data = text.split(",") new_id = ObjectId() new_expense = Expense(new_id, data[0], data[1], data[2]) response = myUsers.update({"id": userid}, {'$push': { 'expenses': new_expense.getSchema() }}) logger.info("elements updated: " + str(response["updatedExisting"])) return new_expense.toString()
def new_expense_reply(update: Update, context: CallbackContext) -> int: text = update.message.text logger.info("text:" + str(text)) logger.info("id:" + str(update.message.from_user.id)) event = myDbManager.createExpense(update.message.from_user.id, text) update.message.reply_text( "Nice the following expense has been created:\n" + str(event), reply_markup=markup, ) return CHOOSING
def start(update: Update, context: CallbackContext) -> None: #Send a message when the command /start is issued. try: myDbManager.newUser(update.message.from_user) except: logger.info("error validating the user!") try: update.message.reply_text( "Hi Im Expenses and I ll help you to track your expenses :) ", reply_markup=markup) except TelegramError as e: logger.error(e) return CHOOSING
def delete_expense_choice(update: Update, context: CallbackContext) -> int: list_expenses = myDbManager.getExpensesSelectable( update.message.from_user.id) logger.info("ls:" + str(list_expenses)) message = "" response_list = [] for ex in list_expenses: response_list.append(str(ex["id"])) message += str(ex["id"]) + ") " + str(ex["date"]) + "| " + str( ex["name"]) + " - " + str(ex["price"]) + "€\n\n" markup_ids = ReplyKeyboardMarkup(response_list, one_time_keyboard=True) update.message.reply_text("Your expenses are:\n" + message, reply_markup=markup_ids) context.user_data['list_expenses'] = list_expenses return DELETE_REPLY
def createUserDB(user): response = myUsers.insert_one(user.getSchema()) logger.info("New user create with id:" + str(response.inserted_id))