def call_number(message): user_dict = data.are_in_db(message.chat.id) if user_dict and user_dict['phone_number']: bot.send_message( message.chat.id, 'И снова здраствуйте, {} {}!'.format(user_dict['first_name'], user_dict['last_name'])) state = states.base_state bot.send_message(message.chat.id, state['msg'], reply_markup=methods.generate(state)) return elif user_dict and not user_dict['phone_number']: pass elif not user_dict: user = { 'chat_id': message.chat.id, 'first_name': message.chat.first_name, 'last_name': message.chat.last_name } data.new_record('users', user) state = states.ask_phone bot.send_message(message.chat.id, state['msg'], reply_markup=methods.call_number(state['keyboard']))
def echo_message(message): if message.text == 'Узнать погоду': state = states.choose_date bot.send_message(message.chat.id, state['msg'], reply_markup=methods.generate(state)) else: bot.reply_to(message.chat.id, message.text)
def inline_answer(callback): # нужно написать модуль изменения состояния чата с гет и пост запросами print(callback) state = state_handler[callback.data] new_state = state_handler[state['next_state']] bot.edit_message_text(chat_id=callback.message.chat.id, message_id=callback.message.message_id, text=new_state['msg'], reply_markup=methods.generate(new_state))
def check_contact(message): # The user send their own contact? if message.from_user.id == message.contact.user_id: # yes bot.send_message( message.chat.id, 'Спасибо, {} {}!'.format(message.chat.first_name, message.chat.last_name)) data.update_phone_number(message.chat.id, message.contact.phone_number) state = states.base_state bot.send_message(message.chat.id, state['msg'], reply_markup=methods.generate(state)) else: # no state = states.ask_phone bot.send_message(message.chat.id, 'Попробуйте отправить {}'.format(state['msg']), methods.call_number(state['keyboard']))
def main(): logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.DEBUG) if len(sys.argv) < 3: logging.error("Usage: python {} <data-path> <json-out>".format(sys.argv[0])) return path = sys.argv[1] if not os.path.exists(path): logging.error("Not exists path") return test_methods = methods.generate() # metadata of device results = { "?": { "cpuinfo": cpuinfo.get_cpu_info(), "memory": psutil.virtual_memory().total, } } for name, method in test_methods.items(): logging.info("[+] " + name) test_result = run_test(method, path) results[name] = test_result if "*" in test_result: ratio = test_result["*"]["compressed_size"] / test_result["*"]["size"] * 100 c_speed = test_result["*"]["size"] / test_result["*"]["compressed_time"] dc_speed = test_result["*"]["size"] / test_result["*"]["decompressed_time"] logging.info(">>> SUM: ratio {:6.3f}% , compress speed {:7.3f} MB/s , decompress speed {:7.3f} MB/s".format(ratio, c_speed / (1024 ** 2), dc_speed / (1024 ** 2))) else: logging.error("Unknown Error! Maybe out of memory") json_path = sys.argv[2] with open(json_path, "w") as f: json.dump(results, f) logging.info("[!] Done")