Best Python code snippet using avocado_python
__init__.py
Source:__init__.py
...16 for seq in seq_seq:17 if item in seq:18 return True19 return False20def is_script(string, script, ignore=['Inherited', 'Common', 'Unknown']):21 """Returns: true if all chars in string belong to script.22 Args:23 string: A string to test (may be a single char).24 script: Script long name, as in Unicode UCD's Scripts.txt (viz.).25 ignore: A list of scripts that will always suceed for matching purposes.26 For example, ASCII punctuation is listed as 'Common', so 'A.' will27 match as 'Latin', and 'ã.' will match as 'Hiragana'. See UAX #2428 for details.29 >>> is_script('A', 'Latin')30 True31 >>> is_script('ArtemÃsia', 'Latin')32 True33 >>> is_script('á¼Ïίνθιον ', 'Latin')34 False35 >>> is_script('Let θι = 3', 'Latin', ignore=['Greek', 'Common', 'Inherited', 'Unknown'])36 True37 >>> is_script('ã¯ãã¯ããã¼ã®', 'Hiragana')38 True39 >>> is_script('ã¯ãã¯:ããã¼ã®.', 'Hiragana')40 True41 >>> is_script('ã¯ãã¯:ããã¼ã®.', 'Hiragana', ignore=[])42 False43 """44 if ignore == None: ignore = []45 ignore_ranges = []46 for ignored in ignore:47 ignore_ranges += RANGES[ignored]48 for char in string:49 cp = ord(char)50 if ((not in_any_seq(cp, RANGES[script.capitalize()]))51 and not in_any_seq(cp, ignore_ranges)):52 return False53 return True54def which_scripts(char):55 """Returns: list of scripts that char belongs to....
main.py
Source:main.py
1import sqlite32from constants import OLD_DATABASE, CREATE_QUERIES, MIGRATE_SECOND, MIGRATE_JOIN3from flask import Flask, jsonify4import logging5logging.basicConfig(encoding='utf-8', level=logging.INFO)6app = Flask(__name__)7def get_sqlite_query(query, base=OLD_DATABASE, is_script=False):8 """ЧиÑаем ÑÑаÑÑÑ Ð±Ð°Ð·Ñ Ð´Ð°Ð½Ð½ÑÑ
"""9 with sqlite3.connect(base) as connection:10 cursor = connection.cursor()11 if is_script:12 result = cursor.executescript(query)13 else:14 result = cursor.execute(query)15 return result.fetchall()16def get_all_by_id(id):17 query = f"""18 SELECT * 19 FROM animals_new20 WHERE id == {id}21 """22 raw = get_sqlite_query(query, is_script=False)23 result_dict = {'id': raw[0][0], 'age_upon_outcome': raw[0][1], 'animal_id': raw[0][2],24 'name': raw[0][3], 'id_type': raw[0][4], 'id_breed': raw[0][5],25 'id_color1': raw[0][6], 'id_color2': raw[0][7], 'dateOfBirth': raw[0][8][0:10],26 'id_outcome_subtype': raw[0][9], 'id_outcome_type': raw[0][10], 'outcome_month': raw[0][11],27 'outcome_year': raw[0][12]}28 return result_dict29# Создание новÑÑ
ÑаблиÑ. ÐÑÐ½Ð¾Ð²Ð½Ð°Ñ ÑаблиÑа + допÑ30get_sqlite_query(CREATE_QUERIES, is_script=True)31# Ðаполнение доп. ÑÐ°Ð±Ð»Ð¸Ñ Ð´Ð°Ð½Ð½Ñми32get_sqlite_query(MIGRATE_SECOND, is_script=True)33# Ðаполнение оÑновной ÑаблиÑÑ Ð°Ð¹Ð´Ð¸Ñниками ÑеÑез JOIN34get_sqlite_query(MIGRATE_JOIN, is_script=False)35# print((get_all_by_id(1)))36@app.route('/<id>/')37def get_by_id(id):38 """ Шаг 1. ÐоиÑк по Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ñ Ñамого Ñвежего """39 logging.info(f'ÐÑем по ID: {id}')40 animal = get_all_by_id(id) # СловаÑÑ Ñ Ð´Ð°Ð½Ð½Ñми по ÐÐÐÐÐУ поÑÑÑ41 logging.info(f'ФÑнкÑÐ¸Ñ Ð¿Ð¾Ð¸Ñка веÑнÑла: {animal}')42 return jsonify(animal)43app.config['JSON_AS_ASCII'] = False44if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!