Exemplo n.º 1
0
async def exchange_rates(message: types.Message):
    try:
        user_id = message.from_user.id
        d = get_lang(user_id)
        update_log(user_id, get_log(user_id) + message.text)
        if message.text == get_dict('calculator', d):
            await bot.send_message(user_id,
                                   get_dict('section', d),
                                   reply_markup=markups.calculator(d))
            set_user_state(user_id, get_state_by_key('S_CALCULATOR'))
        elif message.text == get_dict('back', d):
            await bot.send_message(user_id,
                                   get_dict('general_hint', d),
                                   reply_markup=markups.general(d))
            set_user_state(user_id, get_state_by_key('S_GENERAL'))
        elif message.text == get_dict('main_menu', d):
            await bot.send_message(user_id,
                                   get_dict('main_menu_hint', d),
                                   reply_markup=markups.main_menu(d))
            set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU'))
        else:
            await bot.send_message(user_id,
                                   get_dict('exchange_rates_data', d),
                                   reply_markup=markups.exchange_rates(d))
    except Exception as e:
        logger_app.error(
            "/handlers/exchange_rates.py\nMethod: exchange_rates\n" + str(e))
Exemplo n.º 2
0
async def purchase_currency(message: types.Message):
    try:
        user_id = message.from_user.id
        d = get_lang(user_id)
        update_log(user_id, get_log(user_id) + message.text)
        if message.text == get_dict('back', d):
            await bot.send_message(user_id,
                                   get_dict('section', d),
                                   reply_markup=markups.calculator(d))
            set_user_state(user_id, get_state_by_key('S_CALCULATOR'))
        elif message.text == get_dict('main_menu', d):
            await bot.send_message(user_id,
                                   get_dict('main_menu_hint', d),
                                   reply_markup=markups.main_menu(d))
            set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU'))
        elif message.text == get_dict('other_amount', d):
            await bot.send_message(user_id, get_dict('enter_amount', d))
        else:
            try:
                result = purchase_calculator(int(message.text), d)
                await bot.send_message(user_id, result)
                return
            except ValueError:
                try:
                    result = purchase_calculator(float(message.text), d)
                    await bot.send_message(user_id, result)
                    return
                except ValueError:
                    await bot.send_message(user_id,
                                           get_dict('error_enter_number', d))
    except Exception as e:
        logger_app.error(
            "/handlers/exchange_rates.py\nMethod: purchase_currency\n" +
            str(e))
Exemplo n.º 3
0
async def calculator(message: types.Message):
    try:
        user_id = message.from_user.id
        d = get_lang(user_id)
        update_log(user_id, get_log(user_id) + message.text)
        if message.text == get_dict('purchase_currency', d):
            await bot.send_message(user_id,
                                   get_dict('purchase_warning', d),
                                   reply_markup=markups.cost(d))
            set_user_state(user_id, get_state_by_key('S_PURCHASE_CURRENCY'))
        elif message.text == get_dict('sale_currency', d):
            await bot.send_message(user_id,
                                   get_dict('sale_warning', d),
                                   reply_markup=markups.cost(d))
            set_user_state(user_id, get_state_by_key('S_SALE_CURRENCY'))
        elif message.text == get_dict('back', d):
            await bot.send_message(
                user_id,
                get_dict('cb_currency_rate', d) + ' \n\n ' +
                exchange_rate_parsing.cb_ex_rates + '\n\n\n' +
                get_dict('purchase_sale', d) + '\n\n' +
                exchange_rate_parsing.purchase_sale_ex_rates,
                reply_markup=markups.exchange_rates(d))
            set_user_state(user_id, get_state_by_key('S_EXCHANGE_RATES'))
        elif message.text == get_dict('main_menu', d):
            await bot.send_message(user_id,
                                   get_dict('main_menu_hint', d),
                                   reply_markup=markups.main_menu(d))
            set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU'))
        else:
            await bot.send_message(user_id, get_dict('section', d))
    except Exception as e:
        logger_app.error("/handlers/exchange_rates.py\nMethod: calculator\n" +
                         str(e))
Exemplo n.º 4
0
def getCardBalance(card, expiry):
    try:
        tz = pytz.utc.localize(dt.datetime.utcnow())
        payload = {
            "msgid":
            str(uuid.uuid4()),
            "msgcorrid":
            str(uuid.uuid4()),
            "msgdate":
            str(dt.datetime.utcnow().isoformat(
                sep='T', timespec='milliseconds')) + '+05:00',
            "msgmode":
            "SYNCHRONOUS",
            "msgtype":
            "REQUEST",
            "msgresptype":
            "JSON",
            "msgsource":
            "TlgBot",
            "msgmethod":
            "TlgBot.getCardBalance",
            "msgmethodparams": {
                "card": card,
                "expiry": expiry
            }
        }
        return send_request(payload)
    except Exception as e:
        logger_app.error("/handlers/api.py\nMethod: getCardBalance\n" + str(e))
Exemplo n.º 5
0
def confirmOperationAuthCard(sessionId, confirmCode):
    try:
        tz = pytz.utc.localize(dt.datetime.utcnow())
        payload = {
            "msgid":
            str(uuid.uuid4()),
            "msgcorrid":
            str(uuid.uuid4()),
            "msgdate":
            str(dt.datetime.utcnow().isoformat(
                sep='T', timespec='milliseconds')) + '+05:00',
            "msgmode":
            "SYNCHRONOUS",
            "msgtype":
            "REQUEST",
            "msgresptype":
            "JSON",
            "msgsource":
            "TlgBot",
            "msgmethod":
            "TlgBot.confirmOperation",
            "msgmethodparams": {
                "sessionId": sessionId,
                "confirmCode": confirmCode
            }
        }
        return send_request(payload)
    except Exception as e:
        logger_app.error("/handlers/api.py\nMethod: confirmOperation\n" +
                         str(e))
Exemplo n.º 6
0
async def sms(message: types.Message):
    try:
        user_id = message.from_user.id
        d = get_lang(user_id)
        update_log(user_id, get_log(user_id) + message.text)
        if message.text == get_dict('cancel', d):
            await bot.send_message(user_id,
                                   get_dict('section', d),
                                   reply_markup=markups.payments(d))
            set_user_state(user_id, get_state_by_key('S_PAYMENTS'))
        else:
            sessionId = get_session_id(user_id)
            confirmCode = str(message.text)
            errorCode = (api.confirmOperationAuthCard(
                sessionId, confirmCode))['msgrespdata']['errorCode']

            if errorCode == '0':
                await bot.send_message(user_id,
                                       get_dict(
                                           'success_transfer_card_to_card', d),
                                       reply_markup=markups.payments(d))
                set_user_state(user_id, get_state_by_key('S_PAYMENTS'))
            else:
                await bot.send_message(user_id,
                                       get_dict('error_payment', d),
                                       reply_markup=markups.payments(d))
                set_user_state(user_id, get_state_by_key('S_PAYMENTS'))
    except Exception as e:
        logger_app.error(
            "/handlers/individual_cards.py\nMethod: new_card_number\n" +
            str(e))
Exemplo n.º 7
0
def payP2p(from_card, expiry, to_card, amount):
    try:
        tz = pytz.utc.localize(dt.datetime.utcnow())
        payload = {
            "msgid":
            str(uuid.uuid4()),
            "msgcorrid":
            str(uuid.uuid4()),
            "msgdate":
            str(dt.datetime.utcnow().isoformat(
                sep='T', timespec='milliseconds')) + '+05:00',
            "msgmode":
            "SYNCHRONOUS",
            "msgtype":
            "REQUEST",
            "msgresptype":
            "JSON",
            "msgsource":
            "TlgBot",
            "msgmethod":
            "TlgBot.payP2p",
            "msgmethodparams": {
                "fromCard": from_card,
                "expiry": expiry,
                "toCard": to_card,
                "amount": amount
            }
        }
        return send_request(payload)
    except Exception as e:
        logger_app.error("/handlers/api.py\nMethod: authCard\n" + str(e))
Exemplo n.º 8
0
async def contribution(message: types.Message):
    try:
        user_id = message.from_user.id
        d = get_lang(user_id)
        update_log(user_id, get_log(user_id) + message.text)
        if message.text == get_dict('national_currency', d):
            await bot.send_message(
                user_id,
                get_dict('section', d),
                reply_markup=markups.contribution_online_branch(d))
            set_user_state(
                user_id, get_state_by_key('S_CONTRIBUTION_NATIONAL_CURRENCY'))
        elif message.text == get_dict('contribution_us_dollar', d):
            await bot.send_message(
                user_id,
                get_dict('section', d),
                reply_markup=markups.contribution_online_branch(d))
            set_user_state(user_id,
                           get_state_by_key('S_CONTRIBUTION_US_DOLLAR'))
        elif message.text == get_dict('back', d):
            await bot.send_message(user_id,
                                   get_dict('individual_hint', d),
                                   reply_markup=markups.individual(d))
            set_user_state(user_id, get_state_by_key('S_INDIVIDUAL'))
        elif message.text == get_dict('main_menu', d):
            await bot.send_message(user_id,
                                   get_dict('main_menu_hint', d),
                                   reply_markup=markups.main_menu(d))
            set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU'))
        else:
            await bot.send_message(user_id, get_dict('section', d))
    except Exception as e:
        logger_app.error(
            "/handlers/individual_deposit.py\nMethod: contribution\n" + str(e))
Exemplo n.º 9
0
async def minibank(message: types.Message):
    try:
        user_id = message.from_user.id
        d = get_lang(user_id)
        update_log(user_id, get_log(user_id) + message.text)
        i = 0
        if message.text == get_dict('back', d):
            await bot.send_message(user_id,
                                   get_dict('main_menu_hint', d),
                                   reply_markup=markups.branches(d))
            set_user_state(user_id, get_state_by_key('S_BRANCH'))
        elif message.text == get_dict('main_menu', d):
            await bot.send_message(user_id,
                                   get_dict('section', d),
                                   reply_markup=markups.main_menu(d))
            set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU'))
        else:
            while i < len(distinct_regions()):
                if message.text == get_region(distinct_regions()[i][0], d):
                    await bot.send_message(user_id,
                                           get_dict('section', d),
                                           reply_markup=markups.minibank(
                                               distinct_regions()[i][0], d))
                    set_user_state(user_id, distinct_regions()[i][0] + 'M')
                    break
                i = i + 1
    except Exception as e:
        logger_app.error("/handlers/atm.py\nMethod: minibank\n" + str(e))
Exemplo n.º 10
0
def set_p2p_amount(id_oper, from_user_amount):
    try:
        script = 'UPDATE p2p_report SET "FROM_USER_AMOUNT"=(%s) WHERE "ID"=(%s); '
        cur = conn.cursor()
        cur.execute(script, (from_user_amount, id_oper))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: set_p2p_amount\n" + str(e))
Exemplo n.º 11
0
def set_p2p_info(id_oper, status, details, date_time):
    try:
        script = 'UPDATE p2p_report SET "STATUS"=(%s), "DETAILS"=(%s), "DATE_TIME"=(%s) WHERE "ID"=(%s);'
        cur = conn.cursor()
        cur.execute(script, (status, details, date_time, id_oper))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: set_p2p_info\n" + str(e))
Exemplo n.º 12
0
def image_insert(file_id, file_name):
    try:
        script = 'INSERT INTO "BRANCH_IMAGES" ("FILE_ID", "FILE_NAME") VALUES (%s, %s);'
        cur = conn.cursor()
        cur.execute(script, (file_id, file_name))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: image_insert\n" + str(e))
Exemplo n.º 13
0
def get_poll_url(key, lang):
    try:
        script = 'SELECT field_text FROM app_dictionary WHERE key=(%s) AND code_lang=(%s);'
        cur = conn.cursor()
        cur.execute(script, (key, lang))
        return cur.fetchone()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_poll_url\n" + str(e))
Exemplo n.º 14
0
def set_user_state(user_id, state):
    try:
        script = 'UPDATE app_users SET state=(%s) WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (state, str(user_id)))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: set_user_state\n" + str(e))
Exemplo n.º 15
0
def update_log(user_id, log_text):
    try:
        script = "UPDATE log SET log_text=(%s) WHERE user_id=(%s);"
        cur = conn.cursor()
        cur.execute(script, (log_text + "\n", str(user_id)))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: update_log\n" + str(e))
Exemplo n.º 16
0
def get_user(user_id):
    try:
        script = 'SELECT * FROM app_users WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (str(user_id), ))
        return cur.fetchone()
    except (Exception, Error) as e:
        logger_app.error("/database_connection/dbcon.py\nMethod: get_user\n" +
                         str(e))
Exemplo n.º 17
0
def set_timer_sms(user_id, time):
    try:
        script = 'UPDATE app_users SET expire=(%s) WHERE user_id=(%s); '
        cur = conn.cursor()
        cur.execute(script, (time, user_id))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: set_timer_sms\n" + str(e))
Exemplo n.º 18
0
def get_image(file_name):
    try:
        script = 'SELECT "FILE_ID" FROM "BRANCH_IMAGES" WHERE "FILE_NAME"=(%s);'
        cur = conn.cursor()
        cur.execute(script, (file_name, ))
        return cur.fetchone()
    except (Exception, Error) as e:
        logger_app.error("/database_connection/dbcon.py\nMethod: get_image\n" +
                         str(e))
Exemplo n.º 19
0
def get_user_unique_code(unique_code):
    try:
        script = 'SELECT * FROM "USERS_UNIQUE_CODE" WHERE "UNIQUE_CODE"=(%s);'
        cur = conn.cursor()
        cur.execute(script, (str(unique_code), ))
        return cur.fetchone() is not None
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_user_unique_code\n" +
            str(e))
Exemplo n.º 20
0
def set_user_unique_code(user_id, aacct, unique_code):
    try:
        script = 'INSERT INTO "USERS_UNIQUE_CODE" ("USER_ID", "AACCT", "UNIQUE_CODE") VALUES (%s, %s, %s);'
        cur = conn.cursor()
        cur.execute(script, (str(user_id), aacct, unique_code))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: set_user_unique_code\n" +
            str(e))
Exemplo n.º 21
0
def authCard(user_id, cardNumber, expiry, encrypted_card_number):
    try:
        script = 'INSERT INTO cards (user_id, card_number, card_expiry, encrypted_card_number) VALUES (%s, %s, %s, %s);'
        cur = conn.cursor()
        cur.execute(script,
                    (str(user_id), cardNumber, expiry, encrypted_card_number))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error("/database_connection/dbcon.py\nMethod: authCard\n" +
                         str(e))
Exemplo n.º 22
0
def get_region_id(user_id):
    try:
        script = 'SELECT code_region FROM app_users WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (user_id, ))
        row = cur.fetchone()
        return row[0]
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_region_id\n" + str(e))
Exemplo n.º 23
0
def get_region(code, lang):
    try:
        script = 'SELECT "NAME" FROM "REGIONS" WHERE "CODE"=(%s) and "CODE_LANG"=(%s);'
        cur = conn.cursor()
        cur.execute(script, (code, lang))
        row = cur.fetchone()
        return row[0]
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_region\n" + str(e))
Exemplo n.º 24
0
def get_regions(code_lang):
    try:
        script = 'SELECT "NAME" FROM "REGIONS" WHERE "CODE_LANG"=(%s);'
        cur = conn.cursor()
        cur.execute(script, (code_lang, ))
        regions = cur.fetchall()
        return regions
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_regions\n" + str(e))
Exemplo n.º 25
0
def get_to_phone_number_oper(user_id):
    try:
        script = 'SELECT "TO_PHONE_NUMBER" FROM mobile_payments_report WHERE "FROM_USER_ID"=(%s) ORDER BY "ID" DESC LIMIT 1;'
        cur = conn.cursor()
        cur.execute(script, (str(user_id), ))
        return cur.fetchone()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_to_phone_number_oper\n"
            + str(e))
Exemplo n.º 26
0
def set_phone_number(user_id, phone_number):
    try:
        script = 'UPDATE app_users SET phone_number=(%s) WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (phone_number, str(user_id)))
        conn.commit()
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: set_phone_number\n" +
            str(e))
Exemplo n.º 27
0
def get_card(user_id):
    try:
        script = 'SELECT new_card_number, new_card_expiry FROM app_users WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (str(user_id), ))
        row = cur.fetchone()
        return row
    except (Exception, Error) as e:
        logger_app.error("/database_connection/dbcon.py\nMethod: get_card\n" +
                         str(e))
Exemplo n.º 28
0
def get_card_json(user_id):
    try:
        script = 'SELECT * FROM cards WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (str(user_id), ))
        card_json = cur.fetchall()
        return card_json
    except (Exception, Error) as e:
        logger_app.error(
            "/database_connection/dbcon.py\nMethod: get_card_json\n" + str(e))
Exemplo n.º 29
0
def get_news(lang):
    try:
        script = 'SELECT title FROM news WHERE code_lang=(%s);'
        cur = conn.cursor()
        cur.execute(script, (lang, ))
        row = cur.fetchone()
        return row[0]
    except (Exception, Error) as e:
        logger_app.error("/database_connection/dbcon.py\nMethod: get_news\n" +
                         str(e))
Exemplo n.º 30
0
def get_log(user_id):
    try:
        script = 'SELECT log_text FROM log WHERE user_id=(%s);'
        cur = conn.cursor()
        cur.execute(script, (str(user_id), ))
        row = cur.fetchone()
        return row[0]
    except (Exception, Error) as e:
        logger_app.error("/database_connection/dbcon.py\nMethod: get_log\n" +
                         str(e))