def test_availability_of_each_poi(self, poi_results_filename, output_filename): if os.path.exists(output_filename): self.test_availability = ds.load_from_json(output_filename) else: self.test_availability = {} pois_dict = ds.load_from_json(poi_results_filename) for poi in pois_dict: poi_id = poi["id"] if poi_id not in self.test_availability: try: charging_availability_id = poi["dataSources"][ "chargingAvailability"]["id"] url = f"https://{self.base_url}/search/2/chargingAvailability.{self.data_type}?key={self.key}&chargingAvailability={charging_availability_id}" search_request = self.s.get(url) if search_request.status_code == 403: print( "Key not accepted, most likely out of transactions" ) ds.save_json(output_filename, self.test_availability) return self.test_availability else: self.test_availability[poi_id] = { "poi_id": poi_id, "charging_availability_id": charging_availability_id, "availability_data": search_request.json() } except KeyError: print( f"No Charging Availability id for station with id {poi_id}, moving to the next id" ) ds.save_json(output_filename, self.test_availability) return self.test_availability
def __init__(self, config_file): #self.key = "BEAUFvC8jzPyPYNBotRrEIlaOi0fBRPo" #self.key = "p9QAG7A754ZSfW21em3XPfDdfoaZls1x" self.base_url = "api.tomtom.com" self.s = requests.Session() self.failed_brand_search = [] self.nearby_results = {} self.failed_nearby_ids = [] self.detailed_results = {} self.failed_detailed_search_id = [] self.poi_results = [] self.availability_data = {} self.output_pois = [] #self.poi_categories_json = self.s.get(self.categories_url).json()["poiCategories"] config = ds.load_from_json(config_file) self.country = config["country"] self.key = config["key"] self.locId = 0 self.poi_code = config["poi_code"] self.failed_ids = [] self.query = config["query"] self.data_type = config["data_type"] self.days_of_week = config["scheduled_days_of_week"] self.hours = config["scheduled_hours"] self.search_type = config["search_type"] self.availability_ids = config["availability_ids"] self.index_keys = config["index_keys"] self.poi_results_filename = config["poi_results_filename"] self.availability_data_filename = config["availability_data_filename"] self.categories_url = "https://" + self.base_url + "/search/2/poiCategories.{self.data_type}?key=" + self.key + "&[language=EN]" self.poi_results = ds.load_from_json(self.poi_results_filename) """
def temporary_ev_availability(self, numbers, availability_data_filename): self.load_results_dict("uk_ev.json") filename = availability_data_filename if os.path.exists(filename): self.availability_data = ds.load_from_json(filename) self.get_charger_availability_by_index_number(numbers) ds.save_json(filename, self.availability_data)
def ev_availability_by_availabilty_id(self, ids, availability_data_filename): filename = availability_data_filename if os.path.exists(filename): self.availability_data = ds.load_from_json(filename) self.get_charger_availability_by_availability_id(ids) ds.save_json(filename, self.availability_data)
def test_pois(self, poi_dict, input_filename, output_filename): test_results = self.test_availability_of_each_poi(poi_dict ,output_filename) test = ds.load_from_json(input_filename) tested_pois = self.sort_availability_data(test_results) self.tested_pois = tested_pois
def load_nearby_results(self, filename): nearby_results = ds.load_from_json(filename) return nearby_results
def load_results_dict(self, filename: str) : self.results_dict = ds.load_from_json(filename)
def load_petrol_stations(self, filename): results_dict = ds.load_from_json(filename) return results_dict
def load_detailed_results(self, filename): detailed= ds.load_from_json(filename) return detailed