예제 #1
0
 def build_vehicle_availability(self, vehicle, start_time, end_time):
     if isinstance(vehicle, tuple):
         vehicle = self.build_vehicle(*vehicle)
     
     veh_avail = AvailableVehicle()
     veh_avail.vehicle = vehicle
     veh_avail.start_time = start_time
     veh_avail.end_time = end_time
     return veh_avail
예제 #2
0
 def get_vehicle_from_html_data(self, pod, vehicle_info_div, start_time, end_time):
     vehicle_header = vehicle_info_div.find('h4')
     vehicle_name = vehicle_header.text
     
     availability_div = vehicle_info_div.find('div', {'class':'timestamp'})
     availability_p = availability_div.find('p')
     
     reserve_div = vehicle_info_div.find('div', {'class':'reserve'})
     reserve_a = reserve_div.find('a')
     lightbox_script = reserve_a['href']
     
     match = re.match(r"javascript:MV.controls.reserve.lightbox.create\('(?P<start_time>[0-9]*)', '(?P<end_time>[0-9]*)', '(?P<vehicle_id>[0-9]*)', ''\);", lightbox_script)
     vehicleid = match.group('vehicle_id')
     
     model = VehicleModel()
     model.name = vehicle_name
     
     vehicle = Vehicle(vehicleid)
     vehicle.model = model
     vehicle.pod = pod
     
     vehicle_availability = AvailableVehicle()
     vehicle_availability.vehicle = vehicle
     vehicle_availability.start_time = start_time
     vehicle_availability.end_time = end_time
     
     # Since the availability information is in the div too, store it.
     if availability_p['class'] == 'good':
         vehicle_availability.availability = 'full'
         vehicle_availability.score = 1
     elif availability_p['class'] == 'bad':
         vehicle_availability.availability = 'none'
         vehicle_availability.score = 0
     elif availability_p['class'] == 'maybe':
         vehicle_availability.availability = 'part'
         vehicle_availability.score = 0.5
         self.assign_vehicle_availability_stipulation(vehicle_availability, availability_p.text)
     
     return vehicle_availability