Exemplo n.º 1
0
 def get_model():
     mark = json_data['make']['slug'].lower(
     ) if json_data['make']['slug'] else None
     model = json_data['model']['slug'].lower(
     ) if json_data['model']['slug'] else None
     if mark is not None and model is not None:
         return get_model_id(mark, model)
Exemplo n.º 2
0
 def parse_model(self):
     lines = self.parse_from_base_info('Модель', link=True)
     if lines is None:
         return None
     print('model is find')
     lines = lines.get_attribute("href").split('/')
     if lines[-3] == 'drugaya':
         return None
     print('data car models', lines[-4], lines[-3])
     return get_model_id(lines[-4], lines[-3])
Exemplo n.º 3
0
 def find_car_data(self):
     self.car_dict = dict(
         model_id=get_model_id(*self.get_mark_model_name()),
         description=self.parser_description(),
         createdAt=self.parse_date_created(),
         location=self.parse_location(),
         gearbox=self.parse_gearbox(),
         cleared=self.parse_cleared(),
         mileage=self.parse_mileage(),
         engine=self.parse_engine(),
         seller=self.parse_seller(),
         bp_link=self.current_link,
         body=self.parse_body(),
         fuel=self.parse_fuel(),
         image=self.parse_image(),
         updatedAt=timezone.now(),
         last_site_updatedAt=None,
         year=self.parse_year(),
         dtp=self.parse_dtp(),
         sold=False)
     print(self.car_dict)
Exemplo n.º 4
0
    def get_ad_data(self, url):
        """Returns ad's data"""
        data = dict()
        soup = self.get_page(url)

        price_soup = soup.find('td', text='Цена') if soup.find(
            'td', text='Цена') else soup.find('span', text='Цена')
        data['price'] = price_soup.find_next_sibling().find('span').find(
            'span').text.translate(OD)

        year_mil_soup = soup.find('td', text='Год выпуска') if soup.find(
            'td', text='Год выпуска') else soup.find('span',
                                                     text='Год выпуска')
        data['year'] = year_mil_soup.find_next_sibling().find(
            'a').text.translate(OD)
        data['mileage'] = int(year_mil_soup.find_next_sibling().find(
            'span').text.translate(OD)) // 1000

        # engine, fuel
        engine_soup = soup.find('td', text='Двигатель') if soup.find(
            'td', text='Двигатель') else soup.find('span', text='Двигатель')
        data['engine'] = engine_soup.find_next_sibling().find(
            'strong').text[:3]
        fuel = engine_soup.find_next_sibling().find('span').text.replace(
            '(', '').replace(')', '').lower()
        data['fuel'] = FUEL.get(fuel)

        # gearbox
        gearbox_soup = soup.find('td', text='КПП') if soup.find(
            'td', text='КПП') else soup.find('span', text='КПП')
        gearbox = gearbox_soup.find_next_sibling().find('strong').text.lower()
        data['gearbox'] = GEARBOX.get(gearbox)

        # body
        body_soup = soup.find('td', text='Тип кузова') if soup.find(
            'td', text='Тип кузова') else soup.find('span', text='Тип кузова')
        body = body_soup.find_next_sibling().find(
            'strong').text.split()[0].lower()
        data['body'] = BODY.get(body)

        # location
        location_soup = soup.find('td', text='Область') if soup.find(
            'td', text='Область') else soup.find('span', text='Область')
        location = location_soup.find_next_sibling().find('a').text.lower()
        data['location'] = LOCATION_ALL.get(location)

        date_soup = soup.find('td', text='Дата добавления') if soup.find(
            'td', text='Дата добавления') else soup.find(
                'span', text='Дата добавления')
        created = date_soup.find_next_sibling().find('span').text
        data['last_site_updatedAt'] = TZ.localize(
            datetime.strptime(created, '%d.%m.%Y'))

        mark_model = soup.find(
            'div', class_='rst-uix-page-tree rst-uix-radius').find(
                'a').find_next_sibling('a').find_next_sibling(
                    'a').find_next_sibling('a').text

        mark = mark_model.split()[0].lower()
        model = mark_model.split()[1].lower()

        data['model_id'] = get_model_id(mark, model)

        data['description'] = soup.find('div', class_='rst-page-oldcars-item-option-block-container rst-page-oldcars-item-option-block-container-desc rst-uix-block-more').text.strip() if \
            soup.find('div', class_='rst-page-oldcars-item-option-block-container rst-page-oldcars-item-option-block-container-desc rst-uix-block-more') else None

        images_soup = soup.find_all('a',
                                    class_='rst-uix-float-left rst-uix-radius')
        data['image'] = images_soup[0]['href'] if images_soup else None

        data['dtp'] = bool(soup.find('em', text="После ДТП"))
        data['rst_link'] = url
        return data
Exemplo n.º 5
0
 def find_model(self, data: dict):
     return get_model_id(data['markNameEng'], data['modelNameEng'])