Esempio n. 1
0
    def _kia(self, name, url_name, url_id, image_id, colors, start=0, stop=80):

        url = (
            u"http://i{server_id}.kia.ru/upload/models/render/"
            u"{url_name}/{url_id}/{image_id}_{image_name}"
        )

        car_model = CarModel.objects.get(name=u"kia")
        car = Car.objects.get(name=name, model=car_model)
        CarPhoto.objects.filter(car=car).delete()
        print name
        for color_name, color_hex in colors.iteritems():
            print '', color_name
            try:
                color = CarColor.objects.get(hex=color_hex)
            except CarColor.DoesNotExist:
                color = CarColor(name=color_name.lower(), hex=color_hex.upper())
                color.save()
            server_id = 0
            for image_number in xrange(start, stop):
                server_id += 1
                image_name = u'{:0>5}.jpg'.format(image_number)
                _url = url.format(
                    server_id=server_id,
                    url_name=url_name,
                    url_id=url_id,
                    image_id=image_id,
                    image_name=image_name
                )
                response = requests.get(_url)
                if response.status_code != 200:
                    print image_number, response.status_code
                    break

                car_photo = CarPhoto(car=car, color=color)
                car_photo.image.save(
                    image_name,
                    ContentFile(response.content),
                    save=True)
                car_photo.save()
                if server_id > 9:
                    server_id = 0
Esempio n. 2
0
    def _hyundai(self, name, colors, start=1, stop=50):

        url = (
            u"http://hyundai-kanavto.ru/media/images/360/"
            u"{car}/{color}/{image_name}")

        car_model = CarModel.objects.get(name=u"huyndai")
        car = Car.objects.get(name=name, model=car_model)
        CarPhoto.objects.filter(car=car).delete()
        print name
        for color_name, color_hex in colors.iteritems():
            print '', color_name
            try:
                color = CarColor.objects.get(hex=color_hex)
            except CarColor.DoesNotExist:
                color = CarColor(name=color_name.lower(), hex=color_hex.upper())
                color.save()

            for image_number in xrange(start, stop):
                image_name = u'{:0>2}.png'.format(image_number)
                _url = url.format(
                    car=car.name,
                    color=color_name,
                    image_name=image_name
                )
                response = requests.get(_url)
                if response.status_code != 200:
                    print image_number, response.status_code
                    break

                car_photo = CarPhoto(car=car, color=color)
                car_photo.image.save(
                    image_name,
                    ContentFile(response.content),
                    save=True)
                car_photo.save()