Example #1
0
    def test_URL_UK(self):
        gh = Geizhals("https://cenowarka.pl/apple-iphone-x-64gb-szary-a1688629.html", "UK")
        device = gh.parse()

        # avoid banning from website
        sleep(uniform(1, 10))

        self.assertEqual(device.name, "Apple iPhone X 64GB grey")
Example #2
0
    def test_URL_DE(self):
        gh = Geizhals("https://geizhals.de/apple-iphone-x-64gb-grau-a1688629.html", "DE")
        device = gh.parse()

        # avoid banning from website
        sleep(uniform(1, 10))

        self.assertEqual(device.name, "Apple iPhone X 64GB grau")
Example #3
0
    def test_ID_PL(self):
        gh = Geizhals(1688629, "PL")
        device = gh.parse()

        # avoid banning from website
        sleep(uniform(1, 10))

        self.assertEqual(device.name, "Apple iPhone X 64GB szary")
Example #4
0
    def __init__(self, name, description, product_id, domain):
        """Initialize the sensor."""

        # internal
        self._name = name
        self._geizhals = Geizhals(product_id, domain)
        self._device = Device()

        # external
        self.description = description
        self.product_id = product_id
Example #5
0
class Geizwatch(Entity):
    """Implementation of Geizwatch."""
    def __init__(self, name, description, product_id, domain):
        """Initialize the sensor."""
        from geizhals import Device, Geizhals

        # internal
        self._name = name
        self._geizhals = Geizhals(product_id, domain)
        self._device = Device()

        # external
        self.description = description
        self.product_id = product_id

    @property
    def name(self):
        """Return the name of the sensor."""
        return self._name

    @property
    def icon(self):
        """Return the icon for the frontend."""
        return ICON

    @property
    def state(self):
        """Return the best price of the selected product."""
        if not self._device.prices:
            return None

        return self._device.prices[0]

    @property
    def device_state_attributes(self):
        """Return the state attributes."""
        while len(self._device.prices) < 4:
            self._device.prices.append('None')
        attrs = {
            'device_name': self._device.name,
            'description': self.description,
            'unit_of_measurement': self._device.price_currency,
            'product_id': self.product_id,
            'price1': self._device.prices[0],
            'price2': self._device.prices[1],
            'price3': self._device.prices[2],
            'price4': self._device.prices[3]
        }
        return attrs

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self):
        """Get the latest price from geizhals and updates the state."""
        self._device = self._geizhals.parse()
Example #6
0
    def __init__(self, name, description, product_id, domain):
        """Initialize the sensor."""
        from geizhals import Device, Geizhals

        # internal
        self._name = name
        self._geizhals = Geizhals(product_id, domain)
        self._device = Device()

        # external
        self.description = description
        self.product_id = product_id
Example #7
0
class Geizwatch(Entity):
    """Implementation of Geizwatch."""

    def __init__(self, name, description, product_id, domain):
        """Initialize the sensor."""
        from geizhals import Device, Geizhals

        # internal
        self._name = name
        self._geizhals = Geizhals(product_id, domain)
        self._device = Device()

        # external
        self.description = description
        self.product_id = product_id

    @property
    def name(self):
        """Return the name of the sensor."""
        return self._name

    @property
    def icon(self):
        """Return the icon for the frontend."""
        return ICON

    @property
    def state(self):
        """Return the best price of the selected product."""
        if not self._device.prices:
            return None

        return self._device.prices[0]

    @property
    def device_state_attributes(self):
        """Return the state attributes."""
        while len(self._device.prices) < 4:
            self._device.prices.append('None')
        attrs = {'device_name': self._device.name,
                 'description': self.description,
                 'unit_of_measurement': self._device.price_currency,
                 'product_id': self.product_id,
                 'price1': self._device.prices[0],
                 'price2': self._device.prices[1],
                 'price3': self._device.prices[2],
                 'price4': self._device.prices[3]}
        return attrs

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self):
        """Get the latest price from geizhals and updates the state."""
        self._device = self._geizhals.parse()
Example #8
0
    # iPhone('XS', 256, 1319),
    # iPhone('XS', 512, 1549),
    #
    iPhone('XS Max', 64, 'grau', 'https://geizhals.de/apple-iphone-xs-max-64gb-grau-a1887140.html'),
    # iPhone('XS Max', 256, 1419),
    # iPhone('XS Max', 512, 1649),
    #
    iPhone('XR', 64, 'schwarz', 'https://geizhals.de/apple-iphone-xr-64gb-schwarz-a1887154.html'),
    #iPhone('XR', 128, 'schwarz', 'https://geizhals.de/apple-iphone-xr-128gb-schwarz-a1887151.html'),
    #iPhone('XR', 256, 'schwarz', 'https://geizhals.de/apple-iphone-xr-256gb-schwarz-a1887121.html'),
    #iPhone('X', 64, 'grau', 'https://geizhals.de/apple-iphone-x-64gb-grau-a1688629.html'),
]


for iphone in iphones:
    iphone.geizhals_price = Geizhals(iphone.geizhals_url).getBestPrice()
    offers = kleinanzeigen.getOffers(iphone.toKleinanzeigen())
    valuable_price = iphone.geizhals_price*float(0.9)

    messages = []
    for offer in offers:
        if offer.price < valuable_price:
            existing_offer = dynamodb.get_item(constant.TABLE_OFFERS, offer.toItemKey())
            if existing_offer is None:
                offer.compared_to_geizhals = 100 - (offer.price * 100 / iphone.geizhals_price) if offer.price is not None else None
                if (offer.compared_to_geizhals >= 15):
                    messages.append(offer.toSlackMessage())
                dynamodb.put_item(constant.TABLE_OFFERS, offer.toJson())
            else:
                print 'Exists: ' + existing_offer['title'] + ' ' + str(existing_offer['price'])