def parse_brands(): """ Получение и запись списка брендов в таблицу brands """ logging.info("Парсинг брендов") soup = get_soup_page_by_link('https://proactions.ru/brands/') lists = soup.find(id='content').findAll('li') count = 0 for e in lists: try: articles = e.a.attrs if articles['href']: Brand.create(name=e.text, link='https://proactions.ru' + e.a.attrs['href']) count += 1 except Exception as ex: logging.error(str(ex)) logging.info(f'Записано {count} брендов')
def test_create_db_and_record(): create_db_tables() gibson = Brand.create(name='Gibson') usa = SubBrand.create(name='USA', brand=gibson) les_paul = Range.create(name='Les Paul', brand=gibson) standard = Model.create(name='Standard', brand=gibson) guitar = Guitar.create(variant=None, year=2018, price=3399, brand=gibson, sub_brand=usa, range_name=les_paul, model=standard)