def build_vehicle(self, vehicleid, podid, pod_name, model_name): model = VehicleModel() model.name = model_name pod = Pod(podid) pod.name = pod_name vehicle = Vehicle(vehicleid) vehicle.pod = pod vehicle.model = model return vehicle
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
def build_vehicle_from_td_element(self, td): pod_a = td.find('a') pod_url = pod_a['href'] pod_names = pod_a.text url_match = re.match(r'my_fleet\.php\?mv_action=show&_r=\d+&pk=(?P<pod_id>\d+)', pod_url) podid = url_match.group('pod_id') vehicle_model, pod_name = \ self.decode_vehicle_name_info_from_element(pod_a) pod = Pod(podid) pod.url = pod_url pod.name = pod_name model = VehicleModel() model.name = vehicle_model vehicle = Vehicle(None) vehicle.model = model vehicle.pod = pod return vehicle