def save_models(): all_auto = model_auto() for auto in all_auto: for brand in Brands.select().where(Brands.brand == auto['brand']): # print(brand.brand) for model in auto['models']: Models.create(brand=brand, models=model)
def insertcomissionpartners(): if request.method == 'POST': valbrandname = request.form['brandname'] valproductname = request.form['productname'] valnumberofproducts = request.form['numberofproducts'] valcouponcode = request.form['couponcode'] valbrandemail = request.form['brandemail'] valbrandcontactname = request.form['brandcontactname'] valbrandcontactnumber = request.form['brandcontactnumber'] #add to database valbrandid = db.session.query(func.max(Brands.brandID)).scalar() + 1 brand_row = Brands(brandID=valbrandid, brandName=valbrandname, productName=valproductname, totalProducts=valnumberofproducts, availableProducts=valnumberofproducts, couponCode=valcouponcode, emailID=valbrandemail, contactName=valbrandcontactname, contactNumber=valbrandcontactnumber) db.session.add(brand_row) db.session.commit() return render_template("Brands.html") return render_template("Brands.html")
def get_model(): all_models = [] name = request.form['name'] brand = Brands.select().where(Brands.brand == name) models = Models.select().where(Models.brand == brand) for model in models: all_models.append(model.models) return jsonify(models=all_models)
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)
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 brand_icon(): all_auto = [] all_brands = brand_auto() for brand in all_brands: brands = {} page = requests.get(brand['url']).text icon = page.split('<div class="brand-icon">')[1].split('</div>')[0] icon = icon.split('<img src="')[1].split('"')[0] print(icon) end = icon[-4:] # resource = requests.get(icon, stream=True) # dir_first_img = './static/icon' # dir = os.makedirs(dir_first_img) # name = dir_first_img + '/' + brand['title'] + end # out = open(name, 'wb') # out.write(resource.raw.read()) # out.close() brands['title'] = brand['title'] brands['url'] = brand['url'] brands['icon'] = './static/icon/' + brand['title'] + end print(brands['icon']) Brands.get_or_create(brand=brands['title'], icon=brands['icon']) all_auto.append(brands) return all_auto
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 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'])