def parse_pop_models(): list_brands = [] page = requests.get('http://catalog.am.ru/').text all_brands = page.split\ ('<div class="au-openable-list__list au-openable-list__list_popular js-openable-list__list_popular">')[1].split\ ('<div class="au-openable-panel js-openable-list__sh">')[0] all_brands = all_brands.split('<a') for brand in all_brands[1:]: brands = {} if brand.find('title') > 0: brands['url'] = brand.split('href="')[1].split('"')[0] brands['title'] = brand.split('title="')[1].split('"')[0] if brands['title'] != 'Ferrari' and brands['title'] != 'TVR': for br in Brands.select().where( Brands.brand == brands['title']): print(br.icon) brands['icon'] = br.icon Pop_Brands.get_or_create(brand=brands['title'], icon=brands['icon'])
def main(): parse_pop_models() # brand_icon() # model_auto() # save_models() # save_year() for brand in Pop_Brands.select().where(Pop_Brands.brand == 'УАЗ'): print(brand.icon) for auto in Models.select().where(Models.brand == brand): print(auto.models)
def about(): brands = Brands.select() brands = brands.order_by(Brands.brand) years = Years.select() years = years.order_by(Years.year.desc()) pop_brands = Pop_Brands.select() pop_brands = pop_brands.order_by(Pop_Brands.brand) return render_template('about.html', brands=brands, years=years, pop_brands=pop_brands)
def index(): brands = Brands.select() brands = brands.order_by(Brands.brand) years = Years.select() years = years.order_by(Years.year.desc()) pop_brands = Pop_Brands.select() pop_brands = pop_brands.order_by(Pop_Brands.brand) print(url_for('static', filename='css/styles.css')) return render_template('index2.html', brands=brands, years=years, pop_brands=pop_brands)
def different_services(service): brands = Brands.select() brands = brands.order_by(Brands.brand) years = Years.select() years = years.order_by(Years.year.desc()) pop_brands = Pop_Brands.select() pop_brands = pop_brands.order_by(Pop_Brands.brand) filename = os.path.join(DIRNAME, service + '.yaml') if not os.path.exists(filename): abort(404) with open(filename) as f: services = yaml.load(f) return render_template('services.html', services=services, brands=brands, years=years, pop_brands=pop_brands)
def different_models(name): brands = Brands.select() brands = brands.order_by(Brands.brand) try: model = Brands.select().where(Brands.brand == name).get() models = Models.select().where(Models.brand == model) except Brands.DoesNotExist: abort(404) years = Years.select() years = years.order_by(Years.year.desc()) pop_brands = Pop_Brands.select() pop_brands = pop_brands.order_by(Pop_Brands.brand) return render_template('brands.html', brands=brands, years=years, pop_brands=pop_brands, model=model, models=models)