greenwheels.py
1 from typing import List 2 3 from scrapy.http import HtmlResponse 4 5 from cache.store import strip_all_get_decimal 6 from models.interface import ProviderInterface, VehicleOption, Calculator 7 8 9 class GreenWheels(ProviderInterface): 10 async def get_vehicles_options(self) -> List[VehicleOption]: 11 pricing_page = self.get_pricing_html()[0] 12 response = HtmlResponse( 13 url=pricing_page.url, body=pricing_page.html, encoding="utf-8" 14 ) 15 16 xpaths = [ 17 "/html/body/main/div[2]/div/div[4]/div/div[1]/div[2]/div/div[1]/div[3]/div[1]/h3", # station per hour 18 "/html/body/main/div[2]/div/div[4]/div/div[1]/div[2]/div/div[1]/div[3]/div[2]/h3", # station per km 19 "/html/body/main/div[2]/div/div[4]/div/div[1]/div[1]/div/div[1]/div[3]/div[1]/h3", # stadsauto per hour 20 "/html/body/main/div[2]/div/div[4]/div/div[1]/div[1]/div/div[1]/div[3]/div[2]/h3", # stadsauto per km 21 ] 22 23 ( 24 station_per_hour, 25 station_per_km, 26 stadsauto_per_hour, 27 stadsauto_per_km, 28 ) = tuple( 29 strip_all_get_decimal(response.xpath(xpath).extract()[0].strip()) 30 for xpath in xpaths 31 ) 32 33 return [ 34 VehicleOption( 35 calculator=Calculator( 36 price_per_minute=station_per_hour / 60, 37 price_per_km=station_per_km, 38 vehicle_request=self.vehicle_request, 39 ), 40 vehicle_image="greenwheels-station.png", 41 provider="Greenwheels", 42 type="Station wagon", 43 ), 44 VehicleOption( 45 calculator=Calculator( 46 price_per_minute=stadsauto_per_hour / 60, 47 price_per_km=stadsauto_per_km, 48 vehicle_request=self.vehicle_request, 49 ), 50 vehicle_image="greenwheels-stadsauto.png", 51 provider="Greenwheels", 52 type="Stadsauto", 53 ), 54 ]