How to use render_message method in prospector

Best Python code snippet using prospector_python

buy_money.py

Source:buy_money.py Github

copy

Full Screen

...11 bot.handlers["buy-money/confirm"] = confirm12 bot.callback_handlers["admin-confirm-tx"] = admin_confirm13 bot.callback_handlers["admin-not-confirm-tx"] = admin_not_confirm14def start(bot, message):15 get_value_message = bot.render_message("get-value-to-buy", currency=main_wallet.get_currency())16 back_to_menu_keyboard = bot.get_keyboard("back-to-menu")17 bot.telegram.send_message(message.u_id, get_value_message, parse_mode="Markdown", reply_markup=back_to_menu_keyboard)18 bot.set_next_handler(message.u_id, "buy-money/get-value")19def get_value(bot, message):20 incorrect_value_message = bot.render_message("incorrect-value-to-buy")21 get_username_message = bot.render_message("get-username-to-buy")22 back_to_menu_keyboard = bot.get_keyboard("back-to-menu")23 message.text = message.text.upper()24 serach_result = re.search("(?P<value>[0-9]{1,}([,.][0-9]{1,}){0,1}).*(?P<currency>(BTC|RUB))", message.text)25 if serach_result:26 value, currency = float(serach_result.group("value")), serach_result.group("currency")27 if currency == "RUB":28 rub = value29 btc = value/(main_wallet.get_currency() * 1.1)30 else:31 btc = value32 rub = value*(main_wallet.get_currency() * 1.1)33 tx = {"rub_value": rub,34 "btc_value": btc,35 "uid": message.u_id}36 bot.user_set(message.u_id, "buy-btc:tx", tx)37 bot.telegram.send_message(message.u_id, get_username_message, parse_mode="Markdown", reply_markup=back_to_menu_keyboard)38 bot.set_next_handler(message.u_id, "buy-money/get-username") 39 else:40 bot.telegram.send_message(message.u_id, incorrect_value_message, parse_mode="Markdown", reply_markup=back_to_menu_keyboard)41 bot.call_handler("buy-money/start", message)42 return43def get_username(bot, message):44 tx = bot.user_get(message.u_id, "buy-btc:tx")45 confirm_message = bot.render_message("pending-payment", btc=tx["btc_value"], rub=tx["rub_value"])46 card_number_message = bot.render_message("card-number", cards=main_wallet.cards)47 tx_creating_error_message = bot.render_message("tx-creating-error")48 confirm_keyboard = bot.get_keyboard("confirm-purchase")49 if not message.forward:50 username = message.text51 tx["username"] = username52 53 tx_id = main_wallet.add_tx(tx["username"], tx["uid"], tx["btc_value"], tx["rub_value"])54 bot.user_delete(message.u_id, "buy-btc:tx")55 if tx_id == -1:56 bot.telegram.send_message(message.u_id, tx_creating_error_message, parse_mode="Markdown")57 bot.call_handler("main-menu", message)58 return59 bot.user_set(message.u_id, "buy-btc:tx-id", tx_id) 60 bot.telegram.send_message(message.u_id, confirm_message, parse_mode="Markdown", reply_markup=confirm_keyboard)61 bot.telegram.send_message(message.u_id, card_number_message, parse_mode="Markdown", reply_markup=confirm_keyboard)62 bot.set_next_handler(message.u_id, "buy-money/confirm") 63def confirm(bot, message):64 cancelled_message = bot.render_message("tx-cancelled")65 wait_message = bot.render_message("wait-accepting")66 old_tx_message = bot.render_message("old-tx")67 if message.u_id != bot.admin:68 menu_keyboard = bot.get_keyboard("menu-keyboard")69 else:70 menu_keyboard = bot.get_keyboard("admin-menu-keyboard")71 tx_id = bot.user_get(message.u_id, "buy-btc:tx-id")72 73 tx = main_wallet.get_tx(tx_id)74 if not tx:75 bot.telegram.send_message(message.u_id, old_tx_message, parse_mode="Markdown", reply_markup=menu_keyboard)76 return77 if bot.get_key("confirm-purchase", message.text) == "yes":78 bot.telegram.send_message(message.u_id, wait_message, parse_mode="Markdown", reply_markup=menu_keyboard)79 send_confirm_message_to_admin(bot, message, tx_id)80 elif bot.get_key("confirm-purchase", message.text) == "no":81 main_wallet.not_confirm_tx(tx_id)82 bot.user_delete(message.u_id, "buy-btc:tx-id")83 bot.telegram.send_message(message.u_id, cancelled_message, parse_mode="Markdown", reply_markup=menu_keyboard)84 else:85 bot.call_handler("buy-money/get-username", message)86 return 87def send_confirm_message_to_admin(bot, message, tx_id):88 tx = main_wallet.get_tx(tx_id)89 tx_info_message = bot.render_message("tx-info-for-admin", tx=tx)90 tx_confirm_keyboard = bot.get_inline_keyboard("confirm-tx", params={"tx-id":tx_id})91 bot.telegram.send_message(bot.admin, tx_info_message, parse_mode="Markdown", reply_markup=tx_confirm_keyboard)92def admin_confirm(bot, query):93 tx_id = query.data.split("/")[1]94 tx = main_wallet.get_tx(tx_id)95 tx_confirmed_message = bot.render_message("tx-confirmed")96 97 menu_keyboard = bot.get_keyboard("menu-keyboard")98 99 tx_info_message = bot.render_message("tx-info-for-admin", tx=tx, state=1)100 101 main_wallet.confirm_tx(tx_id)102 bot.telegram.send_message(tx["uid"], tx_confirmed_message, parse_mode="Markdown", reply_markup=menu_keyboard)103 bot.telegram.edit_message_text(chat_id=query.u_id, 104 message_id=query.message.message_id, 105 text=tx_info_message,106 parse_mode="Markdown")107def admin_not_confirm(bot, query):108 tx_id = query.data.split("/")[1]109 tx = main_wallet.get_tx(tx_id)110 tx_not_confirmed_message = bot.render_message("tx-not-confirmed")111 112 menu_keyboard = bot.get_keyboard("menu-keyboard")113 tx_info_message = bot.render_message("tx-info-for-admin", tx=tx, state=2)114 115 main_wallet.not_confirm_tx(tx_id)116 bot.telegram.send_message(tx["uid"], tx_not_confirmed_message, parse_mode="Markdown", reply_markup=menu_keyboard)117 bot.telegram.edit_message_text(chat_id=query.u_id, 118 message_id=query.message.message_id, 119 text=tx_info_message,...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...19 else:20 return template['template']21def colored_str(color: str, message: str) -> str:22 return f"{color}{message}{Style.RESET_ALL}"23def render_message(type_of_message: str, message: str):24 color = Fore.RED if type_of_message == 'error' else Fore.YELLOW if type_of_message == 'warning' else Fore.GREEN25 print(colored_str(color, type_of_message.upper()), message)26 sleep(.35)27def run_command(command: list, err_message: str = '', succ_message: str = ''):28 result = subprocess.run(command)29 if result.returncode == 0:30 render_message('info', succ_message)31 else:32 if 'npm' in command and 'ERR_SOCKET_TIMEOUT' in result.stderr:33 subprocess.run('clear')34 render_message('warning', 'NPM connection error, Retrying download...')35 run_command(command, err_message, succ_message)36 else:37 render_message('error', err_message)38 exit(1)39def main(project_name: str):40 # check if neu is installed on the users device41 render_message('info', f'Creating a NeutralinoJS app with react support.')42 if not cmd_exists('npm'):43 render_message('error', 'NPM is not installed on this machine')44 exit(1)45 else:46 if not cmd_exists('neu'):47 # install neu if does not exit48 render_message('warning', 'neu is not installed on this machine, installing...')49 run_command(['sudo', 'npm', 'install', '-g', '@neutralinojs/neu'], "Can't install neu", 'Neu installed successfully')50 render_message('info', 'Creating a neutralino js app with the codezri/neutralinojs-react template')51 run_command(['neu', 'create', project_name, '--template', 'codezri/neutralinojs-react'], "Can't create project", 'Project created successfuly')52 # changing directory to the current project/react-src53 chdir(f'{project_name}/react-src')54 if cmd_exists('ncu'):55 render_message('info', 'npm check updates found!, upgrading package.json...')56 run_command(['ncu', '-u'], "Can't update package.json", 'Successfullty updated dependencies in package.json')57 render_message('info', 'Installing React and its dependencies with NPM')58 run_command(['npm', 'install'], 'Cant Install React and its dependencies', 'Successfully installed React and its dependencies')59 render_message('info', 'Modifying the template...')60 with open('package.json', 'r') as package_json:61 index_js_template = get_index_template(package_json.read())62 with open('src/index.js', 'w') as index_js:63 index_js.write(index_js_template)64 render_message('info', 'Template modified successfully')65 render_message('info', 'Building react app...')66 run_command(['npm', 'run', 'build'], "Couldn't build React app", "React was built successfully")67 render_message('operation successful!', f''' 68Run `npm start` to start development server in the react-src directory.69And Run `neu run --frontend-lib-dev` in the Project directory70{colored_str(Fore.GREEN, 'Happy Coding!!')}71 ''')72if __name__ == "__main__":73 parser = ArgumentParser(74 prog="neutralino-react", description="create neutralino applications with react templates.")75 parser.add_argument('project_name', type=str)76 args = parser.parse_args()...

Full Screen

Full Screen

send_money.py

Source:send_money.py Github

copy

Full Screen

...12 bot.handlers["send-money/accpet-sending"] = accept_sending13 main_wallet = MainWallet(bot, os.environ.get("PRIVATE_KEY"))14 15def start(bot, message):16 get_address_message = bot.render_message("get-address-to-send")17 back_to_menu_keyboard = bot.get_keyboard("back-to-menu")18 bot.set_next_handler(message.u_id, "send-money/get-address")19 bot.telegram.send_message(message.u_id, get_address_message, reply_markup=back_to_menu_keyboard, parse_mode="Markdown")20def get_address(bot, message):21 if message.u_id != bot.admin:22 wallet = Wallet(bot, message.u_id)23 else:24 wallet = main_wallet25 incorrect_address_message = bot.render_message("incorrect-address-to-send")26 get_value_message = bot.render_message("get-value-to-send", comission=wallet.comission/10**8)27 if not message.forward:28 if not re.search("[0-9|a-z|A-Z]{30,34}", message.text):29 bot.telegram.send_message(message.u_id, incorrect_address_message, parse_mode="Markdown")30 bot.call_handler("send-money", message)31 return 32 bot.user_set(message.u_id, "address-to-send", message.text)33 bot.set_next_handler(message.u_id, "send-money/get-value")34 bot.telegram.send_message(message.u_id, get_value_message, parse_mode="Markdown")35def get_value(bot, message):36 if message.u_id != bot.admin:37 wallet = Wallet(bot, message.u_id)38 else:39 wallet = main_wallet40 incorrect_value_message = bot.render_message("incorrect-value-to-send")41 search_result = re.search("(?P<value>[0-9]{1,}([,.][0-9]{1,}){0,1})", message.text)42 43 if not search_result:44 bot.telegram.send_message(message.u_id, incorrect_value_message, parse_mode="Markdown")45 bot.call_handler("send-money/get-address", message)46 return47 btc_value = search_result.group("value").replace(",", ".")48 bot.user_set(message.u_id, "btc-to-send", float(btc_value) * 10**8)49 address = bot.user_get(message.u_id, "address-to-send")50 accept_sending_message = bot.render_message("accept-sending", btc=btc_value, address=address)51 accept_keyboard = bot.get_keyboard("accept")52 bot.set_next_handler(message.u_id, "send-money/accpet-sending")53 bot.telegram.send_message(message.u_id, accept_sending_message, parse_mode="Markdown", reply_markup=accept_keyboard)54def accept_sending(bot, message):55 if message.u_id != bot.admin:56 wallet = Wallet(bot, message.u_id)57 else:58 wallet = main_wallet59 ready_send_message = bot.render_message("ready-send")60 no_funds_message = bot.render_message("no-funds-to-send")61 push_error_message = bot.render_message("push-error")62 address = bot.user_get(message.u_id, "address-to-send")63 btc_value = bot.user_get(message.u_id, "btc-to-send")64 keyboard = bot.get_keyboard("menu-keyboard")65 if bot.get_key("accept", message.text) == "yes":66 code = wallet.send_money(btc_value, address)67 68 if code == 0:69 bot.telegram.send_message(message.u_id, ready_send_message, parse_mode="Markdown", reply_markup=keyboard) 70 elif code == -1:71 bot.telegram.send_message(message.u_id, no_funds_message, parse_mode="Markdown", reply_markup=keyboard)72 else:73 bot.telegram.send_message(message.u_id, push_error_message, parse_mode="Markdown", reply_markup=keyboard)74 else:75 bot.call_handler("main-menu", message)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful