def button(bot, update): """Callback funtion for the inline keyboard buttons that handles what happens when user chooses an option in the store.""" if update.callback_query.data.split(" ")[-1] in fiirumi.emojis: fiirumi.vote_message(bot, update) return if not is_registered(bot, update): return query = update.callback_query if query.data == "Poistu": query.edit_message_text(text="Osto keskeytetty") return user = update.effective_user.id time = datetime.datetime.today().isoformat() price = db.get_price(query.data) name = db.get_user(user)[0][2] #print(price) db.add_transaction(user, name, query.data, time, price) db.update_balance(user, -price) saldo = db.get_balance(user) #print(saldo) query.edit_message_text(text="Ostit tuotteen: {}.\n\nSaldo: {:.2f}€".format(query.data, saldo / 100))
def handle_payment(session, invoice): logger.debug("Incoming payment\n{}".format(invoice)) try: amount = int(invoice.value) amount_str = str(amount) if amount <= 0: raise except: amount = None amount_str = u"💯" memo = invoice.memo try: dbinv = session.query(db.Invoice).filter( db.Invoice.payment_request == invoice.payment_request).one() except: # sqlalchemy.orm.exc.NoResultFound logger.critical("Unable to find owner of settled invoice {}!".format( invoice.payment_request)) return db.add_transaction(session, dbinv.user, amount, invoice.payment_request) logger.info("Settled invoice {} for user {}".format(dbinv, dbinv.user)) session.commit() # Notify owner of invoice message = u"💵 Received *{}* satoshis for invoice _{}_".format( amount_str, memo) updater.bot.send_message(chat_id=dbinv.user.telegram_id, text=message, parse_mode=telegram.ParseMode.MARKDOWN)
def send(): res = " " tr = "" if request.method == "POST": user_from = request.form["ids_from"].strip() user_to = request.form["ids_to"].strip() count = request.form["count"].strip() print(db.get_name(user_from)) try: if not db.get_name(user_from) or not db.get_name(user_to): res = "Такого пользователя нет" elif user_to == user_from: res = "Вы пытаетесь перевести деньги самому себе" elif not db.sumbit_coins(user_from)[1] >= int(count) and int( count) > 0: res = "Недостаточно монет" else: res = 0 for i in range(int(count)): db.add_transaction(user_from, user_to) tr = { "from": db.get_name(user_from), "to": db.get_name(user_to), "count": count, "time": str(datetime.utcnow()) } except Exception as e: print(e) res = "Укажите кол-во монет" return render_template('send.html', res=res, tr=tr)
def nosta(update, context): """Withdraw money from account.""" maara = 0 try: maara = int(float(update.message.text.replace(",", ".")) * 100) if maara < 0: raise ValueError except ValueError: context.bot.send_message(update.message.chat.id, "Antamasi luku ei kelpaa. Nosto keskeytetty.", reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END user = update.effective_user.id time = datetime.datetime.today().isoformat() name = db.get_user(user)[0][2] db.update_balance(update.effective_user.id, -maara) db.add_transaction(user, name, "NOSTO", time, maara) saldo = db.get_balance(update.effective_user.id) context.bot.send_message( update.message.chat.id, "Rahan nostaminen saldosta onnistui. Saldosi on nyt {:.2f}€".format( saldo / 100), reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END
def import_transactions(): service = build('sheets', 'v4', credentials=google_auth.creds, cache_discovery=False) sheet = service.spreadsheets() result = sheet.values().get(spreadsheetId=config.TRANSACTIONS_SHEET_ID, range="A1:F").execute()["values"] values = list( map(lambda x: (int(x[1]), x[3], x[5], int(float(x[4]))), result[1:])) print("Importing transactions (first 10 shown): ", values[:10]) db.delete_transactions() for i in values: db.add_transaction(int(i[0]), None, i[1], i[2], int(i[3])) return len(values)
def import_transactions(): service = build('sheets', 'v4', credentials=creds) sheet = service.spreadsheets() result = sheet.values().get(spreadsheetId=settings.secrets["sheets"]["tapahtumat"], range="A1:F").execute()["values"] print(result[:10]) values = list(map(lambda x: (int(x[1]), x[3], x[5], int(float(x[4]))), result[1:])) print(values[:10]) #values = list(map(lambda x: (x[1], x[3], x[5], x[4]), result)) db.delete_transactions() for i in values: try: db.add_transaction(int(i[0]), None, i[1], i[2], int(i[3])) except: pass #print(i) return len(values)
def import_transactions(): service = build('sheets', 'v4', credentials=google_auth.creds) sheet = service.spreadsheets() result = sheet.values().get(spreadsheetId=config.TRANSACTIONS_SHEET_ID, range="A1:F").execute()["values"] print(result[:10]) values = list( map(lambda x: (int(x[1]), x[3], x[5], int(float(x[4]))), result[1:])) print(values[:10]) #values = list(map(lambda x: (x[1], x[3], x[5], x[4]), result)) db.delete_transactions() for i in values: try: db.add_transaction(int(i[0]), None, i[1], i[2], int(i[3])) except: pass #print(i) return len(values)
def lisaa(bot, update): """Add money to account.""" maara = 0 try: maara = int(float(update.message.text.replace(",", ".")) * 100) if maara < 0: raise ValueError except ValueError: bot.send_message(update.message.chat.id, "Antamasi luku ei kelpaa. Lisääminen keskeytetty.", reply_markup = ReplyKeyboardRemove()) return ConversationHandler.END user = update.effective_user.id time = datetime.datetime.today().isoformat() name = db.get_user(user)[0][2] db.update_balance(update.effective_user.id, maara) db.add_transaction(user, name, "PANO", time, maara) saldo = db.get_balance(update.effective_user.id) bot.send_message(update.message.chat.id, "Saldon lisääminen onnistui. Saldosi on nyt {:.2f}€".format(saldo / 100), reply_markup = ReplyKeyboardRemove()) return ConversationHandler.END
ret = stub.SendPaymentSync( ln.SendRequest(payment_request=payment_request), timeout=GRPC_TIMEOUT) except Exception, e: update.message.reply_markdown(messages.exception(e)) raise e if ret.payment_route \ and ret.payment_route.total_amt > 0: # Payment successfully went through sent_amount = ret.payment_route.total_amt num_hops = len(ret.payment_route.hops) fee_amount = sent_amount - satoshis logger.info("{} sent payment of {} satoshis to {}".format( user, sent_amount, destination)) db.add_transaction(session, user, -sent_amount, payment_request) session.commit() update.message.reply_markdown( messages.payment_sent(sent_amount, fee_amount)) else: if ret.payment_error: update.message.reply_text("Could not send payment: `{}`".format( ret.payment_error), parse_mode=telegram.ParseMode.MARKDOWN) logger.info("Error paying {}: {}".format(payment_request, ret.payment_error)) else: update.message.reply_text("Could not send payment") logger.info("Error paying {}".format(payment_request))