def get_confirm_payments_keyboard(bill_id, creditor_id, trans): pending = trans.get_pending_payments(bill_id, creditor_id) kb = [] for payment in pending: btn = InlineKeyboardButton( text='{} {}{:.4f}'.format( utils.format_name(payment[4], payment[2], payment[3]), const.EMOJI_MONEY_BAG, payment[1], ), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_CONFIRM_BILL_PAYMENT, { const.JSON_BILL_ID: bill_id, const.JSON_PAYMENT_ID: payment[0] })) kb.append([btn]) back_btn = InlineKeyboardButton( text="Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) kb.append([back_btn]) return InlineKeyboardMarkup(kb)
def get_manage_bill_keyboard(bill_id, trans): bill_name, __, __, __ = trans.get_bill_gen_info(bill_id) share_btn = InlineKeyboardButton(text="📮 Share Bill for Collaboration", switch_inline_query=bill_name) refresh_btn = InlineKeyboardButton( text="🔄 Refresh Bill", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) share_items = InlineKeyboardButton( text="🙋 Add yourself to Item(s)", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_SHARE_ITEMS_KB, {const.JSON_BILL_ID: bill_id})) share_else_items = InlineKeyboardButton( text="💁 Add someone to Item(s)", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_ADD_SOMEONE, {const.JSON_BILL_ID: bill_id})) calc_bill_btn = InlineKeyboardButton( text="⚖ Calculate Split", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_CALCULATE_SPLIT, {const.JSON_BILL_ID: bill_id})) return InlineKeyboardMarkup([[share_btn], [refresh_btn], [share_items], [share_else_items], [calc_bill_btn]])
def get_payment_buttons(bill_id, user_id, trans, debts=None): kb = [] if debts is None: debts, __ = utils.calculate_remaining_debt(bill_id, trans) for debt in debts: text = '💸 Pay ' for debtor in debt['debtors']: if (debtor['debtor'][0] == user_id and debtor['status'] == '(Pending)'): text = '💰 Unpay ' break credtr = debt['creditor'] refresh_btn = InlineKeyboardButton( text="🔄 Refresh Bill", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) pay_btn = InlineKeyboardButton( text=text + utils.format_name(credtr[3], credtr[1], credtr[2]), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_PAY_DEBT, { const.JSON_BILL_ID: bill_id, const.JSON_CREDITOR_ID: credtr[0] })) kb.append([refresh_btn]) kb.append([pay_btn]) return kb
def get_share_items_admin_keyboard(bill_id, trans): keyboard = [] items = trans.get_bill_items(bill_id) for item_id, item_name, __ in items: item_btn = InlineKeyboardButton( text=item_name, callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_SHARE_BILL_ITEM, { const.JSON_BILL_ID: bill_id, const.JSON_ITEM_ID: item_id })) keyboard.append([item_btn]) share_all_btn = InlineKeyboardButton( text='Share all items', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_SHARE_ALL_ITEMS, {const.JSON_BILL_ID: bill_id})) keyboard.append([share_all_btn]) back_btn = InlineKeyboardButton( text='Back', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_MANAGE_BILL_KB, {const.JSON_BILL_ID: bill_id})) keyboard.append([back_btn]) return InlineKeyboardMarkup(keyboard)
def get_force_confirm_payments_keyboard(bill_id, creditor_id, trans): unpaid = trans.get_unpaid_payments(bill_id, creditor_id) kb = [] for payment in unpaid: btn = InlineKeyboardButton( text='✅ {} {}{:.2f}'.format( utils.format_name(payment[5], payment[3], payment[4]), const.EMOJI_MONEY_BAG, payment[1], ), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_FORCE_CONFIRM_PAYMENT, { const.JSON_BILL_ID: bill_id, const.JSON_PAYMENT_ID: payment[0] })) kb.append([btn]) back_btn = InlineKeyboardButton( text="🔙 Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) kb.append([back_btn]) return InlineKeyboardMarkup(kb)
def get_redirect_pay_keyboard(bill_id): refresh_btn = InlineKeyboardButton( text='Refresh', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_SHARE_BILL, {const.JSON_BILL_ID: bill_id})) inspect_btn = InlineKeyboardButton( text='Pay Debts', url='https://telegram.me/WhoPayBot?start=' + bill_id) return InlineKeyboardMarkup([[refresh_btn], [inspect_btn]])
def getDecoratedMap(bot, update, closestParkings, data, distances): road_styles = [{ 'feature': 'road.highway', 'element': 'geomoetry', 'rules': { 'visibility': 'simplified', 'color': '#c280e9' } }, { 'feature': 'transit.line', 'rules': { 'visibility': 'simplified', 'color': '#bababa' } }] dmap = DecoratedMap(style=road_styles) utente = User.objects.get(chat_id=update.message.chat_id) lat = utente.lat lon = utente.lon dmap.add_marker(LatLonMarker(lat, lon, label='S', color='blue')) i = 0 keyboard = [[], [], []] table = [] for p in closestParkings: if "parking" in utente.lastCommand: dmap.add_marker( LatLonMarker(lat=data[p]['geometry']['coordinates'][1], lon=data[p]['geometry']['coordinates'][0], label=str(i + 1))) textButton = createDetailsButtonTextParking(data[p], i) row = createRowParking(data[p], distances[i], i) elif "chargePoint" in utente.lastCommand: dmap.add_marker( LatLonMarker(lat=data[p]['geometry']['coordinates'][1], lon=data[p]['geometry']['coordinates'][0], label=str(i + 1))) textButton = createDetailsButtonTextChargePoint(data[p], i) row = createRowChargePoint(data[p], distances[i], i) table.append(row) keyboard[i].append( InlineKeyboardButton(text=textButton, callback_data=str(p), resize_keyboard=True)) i += 1 url = dmap.generate_url() npArray = np.array(table) df = pd.DataFrame(npArray) df.columns = ['N.', 'Parking Name', 'Free Slots', 'Distance'] ax = render_mpl_table(df, header_columns=0, col_width=1.5) fileName = str(update.message.chat_id) + '.png' plt.savefig(fileName, bbox_inches='tight') baseDir = settings.BASE_DIR picture = open(baseDir + '/' + fileName, 'rb') #img=urllib.request.urlopen(baseDir + '\foo.png').read() bot.sendPhoto(chat_id=update.message.chat_id, photo=picture) print(ax) return url, keyboard
def get_debts_bill_msg(bill_id, trans): bill_name, __, __, __ = trans.get_bill_gen_info(bill_id) share_btn = InlineKeyboardButton(text="Share Bill", switch_inline_query=bill_name) refresh_btn = InlineKeyboardButton( text="Refresh Bill", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) confirm_btn = InlineKeyboardButton( text="Confirm Payments", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_CONFIRM_PAYMENTS_KB, {const.JSON_BILL_ID: bill_id})) kb = InlineKeyboardMarkup([[share_btn], [refresh_btn], [confirm_btn]]) text, pm = utils.get_debts_bill_text(bill_id, trans) return text, pm, kb
def get_new_bill_keyboard(bill_id): modify_items_btn = InlineKeyboardButton( text="📝 Add/Edit Items", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_MODIFY_ITEMS_KB, {const.JSON_BILL_ID: bill_id})) modify_taxes_btn = InlineKeyboardButton( text="💸 Add/Edit Taxes", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_MODIFY_TAXES_KB, {const.JSON_BILL_ID: bill_id})) done_btn = InlineKeyboardButton( text="👍 Done", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_CREATE_BILL_DONE, {const.JSON_BILL_ID: bill_id})) return InlineKeyboardMarkup([[modify_items_btn], [modify_taxes_btn], [done_btn]])
def get_delete_taxes_keyboard(bill_id, trans): kb = get_tax_buttons(bill_id, ACTION_DELETE_SPECIFIC_TAX, trans) back_btn = InlineKeyboardButton( text="Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_MODIFY_TAXES_KB, {const.JSON_BILL_ID: bill_id})) kb.append([back_btn]) return InlineKeyboardMarkup(kb)
def get_edit_items_keyboard(bill_id, trans): kb = get_item_buttons(bill_id, ACTION_GET_EDIT_SPECIFIC_ITEM_KB, trans) back_btn = InlineKeyboardButton( text="Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_MODIFY_ITEMS_KB, {const.JSON_BILL_ID: bill_id})) kb.append([back_btn]) return InlineKeyboardMarkup(kb)
def get_inspect_bill_keyboard(bill_id): kb = [] by_user_btn = InlineKeyboardButton( text="Inspect Bill by Person", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) by_item_btn = InlineKeyboardButton( text="Inspect Bill by Item", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) back_btn = InlineKeyboardButton( text="Inspect Bill by Item", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) kb = [[by_user_btn], [by_item_btn], [back_btn]] return InlineKeyboardMarkup(kb)
def get_pay_items_keyboard(self, bill_id, trans): keyboard = [] keyboard.extend(DisplayPayItemsKB.get_payment_buttons(bill_id, trans)) refresh_btn = InlineKeyboardButton( text='Refresh', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) keyboard.append([refresh_btn]) return InlineKeyboardMarkup(keyboard)
def get_pay_items_admin_keyboard(bill_id, trans): keyboard = [] keyboard.extend(DisplayPayItemsKB.get_payment_buttons(bill_id, trans)) back_btn = InlineKeyboardButton( text='Back', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_MANAGE_BILL_KB, {const.JSON_BILL_ID: bill_id})) keyboard.append([back_btn]) return InlineKeyboardMarkup(keyboard)
def get_redirect_pay_keyboard(bill_id): refresh_btn = InlineKeyboardButton( text='🔄 Refresh', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_SHARE_BILL, {const.JSON_BILL_ID: bill_id} ) ) inspect_btn = InlineKeyboardButton( text='💸 Pay Debts', url='https://telegram.me/{}?start={}'.format( EnvSettings.APP_NAME, bill_id ) ) return InlineKeyboardMarkup([ [refresh_btn], [inspect_btn] ])
def get_share_items_keyboard(bill_id, trans, user_id): keyboard = [] items = trans.get_bill_items(bill_id) refresh_btn = InlineKeyboardButton( text='🔄 Refresh', callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_REFRESH_BILL, {const.JSON_BILL_ID: bill_id})) keyboard.append([refresh_btn]) for item_id, item_name, __ in items: if trans.has_bill_share(bill_id, item_id, user_id): text = "👋 Unshare " + item_name else: text = '☝️ Share ' + item_name item_btn = InlineKeyboardButton( text=text, callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_SHARE_BILL_ITEM, { const.JSON_ITEM_ID: item_id, const.JSON_USER_ID: user_id })) keyboard.append([item_btn]) text = "🙅 Unshare all items" for item_id, item_name, __ in items: if not trans.has_bill_share(bill_id, item_id, user_id): text = '🙌 Share all items' break share_all_btn = InlineKeyboardButton( text=text, callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_SHARE_ALL_ITEMS, { const.JSON_BILL_ID: bill_id, const.JSON_USER_ID: user_id })) keyboard.append([share_all_btn]) return InlineKeyboardMarkup(keyboard)
def get_item_buttons(bill_id, action, trans): keyboard = [] items = trans.get_bill_items(bill_id) for item_id, item_name, __ in items: item_btn = InlineKeyboardButton( text=item_name, callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, action, { const.JSON_BILL_ID: bill_id, const.JSON_ITEM_ID: item_id })) keyboard.append([item_btn]) return keyboard
def get_edit_tax_keyboard(bill_id, tax_id, trans): name, amt = trans.get_tax(tax_id) edit_name_btn = InlineKeyboardButton( text="Edit Name: '{}'".format(name), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_EDIT_SPECIFIC_TAX_NAME, { const.JSON_BILL_ID: bill_id, const.JSON_TAX_ID: tax_id })) edit_amt_btn = InlineKeyboardButton( text="Edit Amount: '{:.2f}'".format(amt), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_EDIT_SPECIFIC_TAX_AMT, { const.JSON_BILL_ID: bill_id, const.JSON_TAX_ID: tax_id })) back_btn = InlineKeyboardButton( text="Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_EDIT_TAX_KB, {const.JSON_BILL_ID: bill_id})) return InlineKeyboardMarkup([[edit_name_btn], [edit_amt_btn], [back_btn]])
def get_edit_item_keyboard(bill_id, item_id, trans): name, price = trans.get_item(item_id) edit_name_btn = InlineKeyboardButton( text="Edit Name: '{}'".format(name), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_EDIT_SPECIFIC_ITEM_NAME, { const.JSON_BILL_ID: bill_id, const.JSON_ITEM_ID: item_id })) edit_price_btn = InlineKeyboardButton( text="Edit Price: '{:.2f}'".format(price), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_EDIT_SPECIFIC_ITEM_PRICE, { const.JSON_BILL_ID: bill_id, const.JSON_ITEM_ID: item_id })) back_btn = InlineKeyboardButton( text="Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_EDIT_ITEM_KB, {const.JSON_BILL_ID: bill_id})) return InlineKeyboardMarkup([[edit_name_btn], [edit_price_btn], [back_btn]])
def get_modify_taxes_keyboard(bill_id): add_tax_btn = InlineKeyboardButton( text="➕ Add tax", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_ADD_TAX, {const.JSON_BILL_ID: bill_id})) edit_tax_btn = InlineKeyboardButton( text="🔃 Edit tax", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_EDIT_TAX_KB, {const.JSON_BILL_ID: bill_id})) del_tax_btn = InlineKeyboardButton( text="➖ Delete tax", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_DELETE_TAX_KB, {const.JSON_BILL_ID: bill_id})) back_btn = InlineKeyboardButton( text="🔙 Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_NEW_BILL_KB, {const.JSON_BILL_ID: bill_id})) return InlineKeyboardMarkup([[add_tax_btn], [edit_tax_btn], [del_tax_btn], [back_btn]])
def get_modify_items_keyboard(bill_id): add_item_btn = InlineKeyboardButton( text="➕ Add item(s)", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_ADD_ITEMS, {const.JSON_BILL_ID: bill_id})) edit_item_btn = InlineKeyboardButton( text="🔃 Edit item", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_EDIT_ITEM_KB, {const.JSON_BILL_ID: bill_id})) del_item_btn = InlineKeyboardButton( text="➖ Delete item", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_DELETE_ITEM_KB, {const.JSON_BILL_ID: bill_id})) back_btn = InlineKeyboardButton( text="🔙 Back", callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_GET_NEW_BILL_KB, {const.JSON_BILL_ID: bill_id})) return InlineKeyboardMarkup([[add_item_btn], [edit_item_btn], [del_item_btn], [back_btn]])
def get_tax_buttons(bill_id, action, trans): keyboard = [] taxes = trans.get_bill_taxes(bill_id) for tax_id, tax_name, __ in taxes: tax_btn = InlineKeyboardButton( text=tax_name, callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, action, { const.JSON_BILL_ID: bill_id, const.JSON_TAX_ID: tax_id })) keyboard.append([tax_btn]) return keyboard
def get_payment_buttons(bill_id, trans, debts=None): kb = [] if debts is None: debts, __ = utils.calculate_remaining_debt(bill_id, trans) for debt in debts: credtr = debt['creditor'] pay_btn = InlineKeyboardButton( text='Pay ' + utils.format_name(credtr[3], credtr[1], credtr[2]), callback_data=utils.get_action_callback_data( MODULE_ACTION_TYPE, ACTION_PAY_DEBT, { const.JSON_BILL_ID: bill_id, const.JSON_CREDITOR_ID: credtr[0] })) kb.append([pay_btn]) return kb
def language(bot, update): lang_de_button = InlineKeyboardButton(text="Deutsch \U0001F1E9\U0001F1EA", callback_data="ch_lang_de") lang_en_button = InlineKeyboardButton(text="Englisch \U0001F1FA\U0001F1F8", callback_data="ch_lang_en") lang_nl_button = InlineKeyboardButton(text="Nederlands \U0001F1F3\U0001F1F1", callback_data="ch_lang_nl") lang_eo_button = InlineKeyboardButton(text="Esperanto \U0001F30D", callback_data="ch_lang_eo") lang_br_button = InlineKeyboardButton(text="Português \U0001F1E7\U0001F1F7", callback_data="ch_lang_br") lang_es_button = InlineKeyboardButton(text="Español \U0001F1EA\U0001F1F8", callback_data="ch_lang_es") lang_ru_button = InlineKeyboardButton(text="Русский \U0001F1F7\U0001F1FA", callback_data="ch_lang_ru") lang_fa_button = InlineKeyboardButton(text="فارسی \U0001F1EE\U0001F1F7", callback_data="ch_lang_fa") lang_keyboard = InlineKeyboardMarkup([[lang_de_button, lang_en_button], [lang_br_button, lang_ru_button, lang_nl_button], [lang_es_button, lang_eo_button, lang_fa_button]]) db = DBwrapper.get_instance() if update.callback_query: # TODO maybe text user in private instead of group! lang_id = db.get_lang_id(update.callback_query.from_user.id) bot.editMessageText(chat_id=update.callback_query.message.chat_id, text=translate("langSelect", lang_id), reply_markup=lang_keyboard, message_id=update.callback_query.message.message_id) else: lang_id = db.get_lang_id(update.message.from_user.id) bot.sendMessage(chat_id=update.message.chat_id, text=translate("langSelect", lang_id), reply_markup=lang_keyboard, message_id=update.message.message_id)
def sendMessageForParkings(closestParkings, data, bot, update): emoticons = [utility.ONE_KEYCAP, utility.TWO_KEYCAP, utility.THREE_KEYCAP] i = 0 for p in closestParkings: message = emoticons[i] + " The parking is: " + data[p]['properties'][ 'title'] + "\n" bot.sendLocation(update.message.chat_id, data[p]['geometry']['coordinates'][1], data[p]['geometry']['coordinates'][0]) keyboard = [[ InlineKeyboardButton("Show Details", callback_data=str(p)) ]] reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text(text=message, reply_markup=reply_markup) i += 1 bot.sendMessage( chat_id=update.message.chat_id, text= "Click on show details to get more informations or start a new search typing /parking" )