Пример #1
0
def select_store_for_purchase(storename, stor_data_path, stor_db, exp_stor_db,
                              stor_exp_data_path):
    """
    Uses user input to match a storename to a storename in the database. If no store is found, takes user through adding a store.
    """
    if storename not in stor_db.keys():
        prompt = f"I cannot filter for the store '{storename}'. Please select the storename for this store and I will remember it for next time. If it is a new store, type 'n': "
        matched_storename = util.select_dict_key_using_integer(
            exp_stor_db,
            prompt,
            quit_str='n',
            print_children=False,
            print_aborting=False)

        if matched_storename == None:
            matched_storename = util.process_input(
                f"Could you enter a storename so I remember this store in the future? "
            )
            # if new store is added, add it to the exp_stor_db, with empty expenses to be added later by user
            exp_stor_db.update({matched_storename: []})
            data_help.write_to_jsonFile(stor_exp_data_path, exp_stor_db)
        stor_db.update({storename: matched_storename})

        data_help.write_to_jsonFile(stor_data_path, stor_db)

    else:
        matched_storename = stor_db[storename]

    return matched_storename, stor_db, exp_stor_db
Пример #2
0
def change_storepair(db_exp_data_fpaths, df, db_exprec_data_fpath, df_rec,
                     exp_stor_data, stor_data, stor_pair_path,
                     exp_stor_data_path, exp_data, budg_db):
    """
    Allows user to change the pairing setup within stor_data, opting for the creation of a new store, or the repairing to a different store name
    """
    bank_storenames = util.select_dict_keys_using_integer(
        stor_data,
        'Please select your bank storename(s) to change its pairing, ',
        print_children=False,
        quit_str='q',
        print_vals=True)

    if bank_storenames != None:
        for bank_storename in bank_storenames:
            user_in = util.get_user_input_for_chars(
                f"\nDo you want to:\n(a) - re-pair [{bank_storename}] to an existing store you setup\n(b) - re-pair [{bank_storename}] to a new store name?\n(q) quit\nType here: ",
                ['a', 'b', 'q'])
            if user_in == 'a':
                stor_exp_keys = list(exp_stor_data.keys())
                stor_exp_keys.sort()
                new_pairing = util.select_from_list(
                    stor_exp_keys,
                    f"\nPlease select a store to pair [{bank_storename}] to, or 'q' to quit: ",
                    abortchar='q',
                    ret_match=True)

            elif user_in == 'b':
                new_pairing = util.process_input(
                    f"\nPlease input your new storename to be used with [{bank_storename}]: "
                )
                exp_stor_data[new_pairing] = [
                ]  # add new storename to exp_stor_data

            elif user_in == 'q':
                new_pairing = None

            if new_pairing is not None:  # None type indicates user quit
                stor_data[
                    bank_storename] = new_pairing  # set the new pairing into the stor_db
                prompt = f"Searching {db_exp_data_fpaths[0]} for any old references to [{bank_storename}]."
                replace_store_in_df(prompt, df, db_exp_data_fpaths[0],
                                    new_pairing, exp_stor_data, budg_db,
                                    exp_stor_data_path, stor_data,
                                    stor_pair_path, bank_storename)
                prompt = f"Searching {db_exprec_data_fpath} for any old references to [{bank_storename}]."
                replace_store_in_df(prompt, df_rec, db_exprec_data_fpath,
                                    new_pairing, exp_stor_data, budg_db,
                                    exp_stor_data_path, stor_data,
                                    stor_pair_path, bank_storename)

                data_help.write_to_jsonFile(stor_pair_path, stor_data)
Пример #3
0
def add_item(update: telegram.Update, context: telegram.ext.CallbackContext):
    command = process_input(update.message.text)
    list_name = 'Pleepapier'
    if '--reserve' in command.arguments or '-r' in command.arguments:
        list_name = 'Reservelijst'
    items = []
    for command in command.value_list:
        item = Item(item_name=command,
                    item_list=list_name,
                    created_by=update.effective_user.first_name)
        items.append(item)
        input_received_message = '"' + command + '"' + ' staat erop!'
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text=input_received_message)
    upsert_records(items)
Пример #4
0
def move_item(update: telegram.Update, context: telegram.ext.CallbackContext):
    command = process_input(update.message.text)
    list_name = 'Pleepapier'
    if '--reserve' in command.arguments or '-r' in command.arguments:
        list_name = 'Reservelijst'
    items = []
    for value in command.value_list:
        item = query_list_item(command=value, list_name=list_name)
        if not item:
            raise ValueError
        item.item_list = 'Pleepapier' if item.item_list == 'Reservelijst' else 'Reservelijst'
        items.append(item)
        moved_message = '"' + item.item_name + '" staat nu op ' + item.item_list
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text=moved_message)
    upsert_records(items)
Пример #5
0
def add_bet(update: telegram.Update, context: telegram.ext.CallbackContext):
    command = process_input(update.message.text)
    bet_description = command.value
    better = command.arguments.get(
        'b') if 'b' in command.arguments else command.arguments.get('better')
    stake = command.arguments.get(
        's') if 's' in command.arguments else command.arguments.get('stake')
    due_date_str = command.arguments.get(
        'd') if 'd' in command.arguments else command.arguments.get('date')

    if better is None or stake is None or due_date_str is None:
        raise ValueError

    due_date = datetime.fromisoformat(due_date_str.value)

    kratje = Kratjes(better=better.value,
                     bet_description=bet_description,
                     stake=stake.value,
                     due_date=due_date)
    upsert_records([kratje])
Пример #6
0
def new(update: telegram.Update, context: telegram.ext.CallbackContext):
    command = process_input(update.message.text)
    list_name = command.value
    response = ''
    try:
        session = db_session()
        existing_list = session.query(ItemList).filter(
            ItemList.list_name == list_name).all()
        if len(existing_list) > 0:
            response += 'Gast "' + list_name + '" bestaat al...'
        else:
            item_list = ItemList(list_name=list_name,
                                 created_by=update.effective_user.first_name)
            session.add(item_list)
            session.commit()
            response += '"' + list_name + '" is aangemaakt!'
        session.close()
    except ValueError:
        response += 'Lullo, je moet wel wat invullen he'
    context.bot.send_message(chat_id=update.effective_chat.id, text=response)
Пример #7
0
def add_insult(update: telegram.Update, context: telegram.ext.CallbackContext):
    command = process_input(update.message.text)
    items = []
    if len(command.value_list) > 3:
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text='Beetje te veel van het goede gozert')
        return
    for value in command.value_list:
        if len(value) > 140:
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text=
                'Jezus lulijzer, hier gelden gewoon twitter regels: max 140 tekens'
            )
            return
        item = Insult(insult=command,
                      created_by=update.effective_user.first_name)
        items.append(item)
    upsert_records(items)
    added_message = 'Goede! Staat erin'
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text=added_message)