How to use execute_query_with_param method in autotest

Best Python code snippet using autotest_python

my_poi.py

Source:my_poi.py Github

copy

Full Screen

...66 bot.send_message(chat_id=message.chat.id, text=text, reply_markup=keyboard)67@bot.message_handler(commands=['reset'])68def reset_command(message):69 chat_id = message.chat.id70 db.execute_query_with_param(connection, db.delete_poi_query, (chat_id,))71 text = 'Выбрана команда /reset Все Ваши места удалены'72 bot.send_message(chat_id=message.chat.id, text=text)73@bot.message_handler(content_types=['location'])74def send_location_command(message):75 chat_id = message.chat.id76 if chat_id not in chat_ids or not chat_ids[chat_id]['is_input_poi']:77 bot.send_message(chat_id=message.chat.id, text='Вначале выберите команду из списка')78 return79 print(message.location)80 print(message.location.latitude)81 print(message.location.longitude)82 chat_ids[chat_id]['location_lat'] = message.location.latitude83 chat_ids[chat_id]['location_lon'] = message.location.longitude84 print('Локация принята')85@bot.message_handler(content_types=['photo'])86def send_photo_command(message):87 chat_id = message.chat.id88 if chat_id not in chat_ids or not chat_ids[chat_id]['is_input_poi']:89 bot.send_message(chat_id=message.chat.id, text='Вначале выберите команду из списка')90 return91 file_info = bot.get_file(message.photo[-1].file_id)92 downloaded_file = bot.download_file(file_info.file_path)93 rphoto = db.resize_image(downloaded_file)94 chat_ids[chat_id]['photo'] = rphoto95 print('Фото принято')96@bot.message_handler()97def handle_message(message):98 # print(message.text)99 chat_id = message.chat.id100 if chat_id not in chat_ids or not chat_ids[chat_id]['is_input_poi']:101 bot.send_message(chat_id=message.chat.id, text='Выберите команду из списка')102 elif chat_ids[chat_id]['input_poi_step'] == 'address':103 chat_ids[chat_id]['address'] = message.text104 # elif chat_ids[chat_id]['input_poi_step'] == 'photo':105 # photo = message.image106 # rphoto = db.resize_image(photo)107 # chat_ids[chat_id]['photo'] = rphoto108 elif chat_ids[chat_id]['input_poi_step'] == 'description':109 chat_ids[chat_id]['description'] = message.text110 # elif chat_ids[chat_id]['input_poi_step'] == 'location':111 # chat_ids[chat_id]['location_lat'] = message.location['latitude']112 # chat_ids[chat_id]['location_lon'] = message.location['longitude']113 # print(chat_ids)114@bot.callback_query_handler(func=lambda x: True)115def callback_worker(callback_query):116 input_poi_step = callback_query.data117 message = callback_query.message118 chat_id = message.chat.id119 if callback_query.data in ['1', '5', '10']:120 pois = db.execute_read_query(connection, db.select_poi_query, (chat_id,), limit=int(callback_query.data))121 if len(pois) == 0:122 bot.send_message(chat_id=message.chat.id, text='Ничего нет')123 return124 # text = f'Показываю {callback_query.data} мест'125 # bot.send_message(chat_id=message.chat.id, text=text)126 for poi in pois:127 text = f'Сохранено {poi[5]} в {poi[6]}'128 bot.send_message(chat_id=message.chat.id, text=text)129 bot.send_message(chat_id=message.chat.id, text=poi[0])130 if poi[1]:131 bot.send_message(chat_id=message.chat.id, text=poi[1])132 # print(poi[0], poi[1])133 photo = poi[2]134 if photo:135 bot.send_photo(chat_id, photo)136 if poi[3] and poi[3]:137 bot.send_location(chat_id, poi[3], poi[4])138 return139 chat_ids[chat_id]['input_poi_step'] = input_poi_step140 if input_poi_step == 'address':141 bot.send_message(chat_id=message.chat.id, text='Введите адрес :')142 if input_poi_step == 'photo':143 bot.send_message(chat_id=message.chat.id, text='Добавьте фото :')144 if input_poi_step == 'description':145 bot.send_message(chat_id=message.chat.id, text='Введите описание :')146 if input_poi_step == 'location':147 bot.send_message(chat_id=message.chat.id, text='Добавьте локацию :')148 if input_poi_step == 'save':149 if not chat_ids[chat_id]['address']:150 bot.send_message(chat_id=message.chat.id, text='Адрес не может быть пустым')151 return152 save_poi(chat_id)153 bot.send_message(chat_id=message.chat.id, text='Место сохранено')154 if input_poi_step == 'notsave':155 notsave_poi(chat_id)156 bot.send_message(chat_id=message.chat.id, text='Место не сохранено')157def clear_input_state(chat_id):158 chat_ids[chat_id]['is_input_poi'] = False159 chat_ids[chat_id]['input_poi_step'] = ''160 chat_ids[chat_id]['address'] = ''161 chat_ids[chat_id]['photo'] = ''162 chat_ids[chat_id]['description'] = ''163 chat_ids[chat_id]['location_lat'] = ''164 chat_ids[chat_id]['location_lon'] = ''165def save_poi(chat_id):166 # print(chat_ids[chat_id])167 cur_date_time = datetime.datetime.now()168 cur_date = cur_date_time.date()169 cur_time = cur_date_time.time()170 date_creation = str(cur_date)171 time_creation = cur_time.strftime('%H:%M:%S')172 db.execute_query_with_param(connection, db.insert_poi_query,173 (chat_id, chat_ids[chat_id]['address'], chat_ids[chat_id]['description'], chat_ids[chat_id]['photo'], chat_ids[chat_id]['location_lat'], chat_ids[chat_id]['location_lon'], date_creation, time_creation))174 clear_input_state(chat_id)175def notsave_poi(chat_id):176 # print(chat_ids[chat_id])177 clear_input_state(chat_id)178def main():179 global connection180 connection = db.create_connection('poi.db')181 db.execute_query(connection, db.create_poi_table_query)182 print('Start')183 bot.polling()184if __name__ == '__main__':185 main()186'''...

Full Screen

Full Screen

postgresql_helper.py

Source:postgresql_helper.py Github

copy

Full Screen

...134 cur.execute('ALTER TABLE IF EXISTS %s RENAME TO %s;', (src_table_name, dest_table_name))135 connection.commit()136 cur.close()137 connection.close()138def execute_query_with_param(query="", config_file_path=CONFIGURATION_FILE_PATH, param=''):139 engine = get_engine(config_file_path)140 connection = engine.connect()141 result = connection.execute(text(query), domain_list=param).scalar()...

Full Screen

Full Screen

db.py

Source:db.py Github

copy

Full Screen

...47 connection.commit()48 # print("Query executed successfully")49 except Error as e:50 print(f"The error '{e}' occurred")51def execute_query_with_param(connection, query, values):52 cursor = connection.cursor()53 try:54 cursor.execute(query, values)55 connection.commit()56 # print("Query executed successfully")57 except Error as e:58 print(f"The error '{e}' occurred")59def execute_read_query(connection, query, values, limit=1):60 cursor = connection.cursor()61 result = None62 try:63 cursor.execute(query, values)64 result = cursor.fetchmany(limit)65 # result = cursor.fetchall()66 return result67 except Error as e:68 print(f"The error '{e}' occurred")69def read_image(filename):70 try:71 fin = open(filename, "rb")72 img = fin.read()73 # img = Image.open(filename)74 return img75 except IOError as e:76 # В случае ошибки, выводим ее текст77 print("Error %d: %s" % (e.args[0], e.args[1]))78 sys.exit(1)79 finally:80 if fin:81 # Закрываем подключение с файлом82 fin.close()83def resize_image(original_image):84 max_size = (320, 240)85 image = Image.open(io.BytesIO(original_image))86 image.thumbnail(max_size, Image.ANTIALIAS)87 # image.show()88 img_byte_arr = io.BytesIO()89 image.save(img_byte_arr, format='JPEG')90 img_byte_arr.seek(0)91 small_image = img_byte_arr.read()92# return small_image93 return sqlite3.Binary(small_image)94# connection = create_connection('poi.db')95# execute_query(connection, create_poi_table_query)96#97# chat_id = '12345678'98# chat_id = '454724133'99# address = 'Москва4'100# description = 'Хорошее место4'101# image = read_image('anypics.ru-5050-480.jpg')102# small_image = resize_image(image)103# photo = sqlite3.Binary(small_image)104# location_lat = '55.753707'105# location_lon = '37.62003'106# cur_date_time = datetime.datetime.now()107# cur_date = cur_date_time.date()108# cur_time = cur_date_time.time()109# date_creation = str(cur_date)110# time_creation = cur_time.strftime('%H:%M:%S')111# execute_query_with_param(connection, insert_poi_query,112# (chat_id, address, description, photo, location_lat, location_lon, date_creation, time_creation))113# execute_query_with_param(connection, delete_poi_query, (chat_id,))114# pois = execute_read_query(connection, select_poi_query, (chat_id,/), limit=1)115# for poi in pois:116# print(poi[0], poi[1])117# poi = pois[0]118# print(poi[0], poi[1])119# photo = poi[2]120# fout = open('output1.jpg', 'wb')121# fout.write(photo)122# fout.close()...

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 autotest 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