def get_all_routes(countries, airports): json = _json_response(ALL_ROUTES_URL, ALL_ROUTES_PARAMS) for outbound_airport in json['airports']: for route in outbound_airport['routes']: if _is_airport_route(route): if outbound_airport['iataCode'] in airports: _outbound_airport = airports[outbound_airport['iataCode']] _outbound_airport.latitude = outbound_airport['coordinates']['latitude'] _outbound_airport.longitude = outbound_airport['coordinates']['longitude'] else: # Add country to countries if outbound_airport['countryCode'].upper() not in countries: _country = Country(outbound_airport['countryCode'].upper()) countries[_country.countryCode] = _country # Add airport to airports + Add airport in corresponding country _country = countries[outbound_airport['countryCode'].upper()] _outbound_airport = Airport(_country, outbound_airport['iataCode'].upper(), outbound_airport['name']) _country.add_airport(_outbound_airport) if _extract_iataCode_from_route(route) in airports: _inbound_airport = airports[_extract_iataCode_from_route(route)] _outbound_airport.add_route(Route(_outbound_airport, _inbound_airport)) return countries, airports
def parse_country_callback(line): country = Country(line) countries.append(country.to_dict()) if settings.ADD_COUNTRY_TO_CITY: countries_dict[country.iso] = country if settings.ONLY_LANGUAGE: for language in country.languages: if language in settings.ONLY_LANGUAGE: match_language_countries_iso.append(country.iso) break
def post(self): newCountry = Model(countryName=request.form.get("countryName"), population=request.form.get("population"), cropland=request.form.get("cropland"), grazing=request.form.get("grazing"), forest=request.form.get("forest"), carbon=request.form.get("carbon"), fish=request.form.get("fish"), earthsRequired=request.form.get("earthsRequired")) newCountry.save() return { "message" : "Successfully created country.", "href": "/countries/"+request.form.get("countryName") }, 201
def get_stations_info(): json = _json_response(ALL_STATIONS_URL) countries, airports = {}, {} for iataCode, info in json.items(): if info['country'] not in countries: countries[info['country']] = Country(info['country']) country = countries[info['country']] airport = Airport(country, iataCode, info['name']) country.add_airport(airport) airports[iataCode] = airport return countries, airports
def setup(coordinates_interval): with open(path_join(BASEPATH, 'input/input.json')) as json_file: settings = json_load(json_file) logging.log_event('Starting the setup', 'main') # Log the start up to the loggin file wsd = {'radius': 6371000, 'wattPerSquareMetre': 1368} country_list = [ Country(c, GHG, data_instance.get_data(c)) for c in data_instance.get_country_names() ] ghg_instance = GHG() data = dict( time=Time(settings['start_year']), albedo=Albedo(), ghg=ghg_instance, countries=country_list, coordinates=create_list_coordinates( coordinates_interval, { 'albedo': Albedo, 'ghg': ghg_instance, 'country_names': data_instance.get_country_with_location( ), # {'country': [long, lat], ...} 'country_instances': country_list, })) earth = World(data, wsd) for c_x in earth.coordinates: for c_y in c_x: c_y.world_instance = earth c_y.calculate_current_temperature() mapping = Mapping(BASEPATH, settings['start_year'], data['time'].time_interval) return earth, data['time'], mapping
def import_country(path): """Import file to save countries in database""" file = os.path.abspath(path) session = get_session() try: with open(file) as csvfile: csv_reader = DictReader(csvfile) with click.progressbar(iterable=csv_reader, show_pos=True) as bar: for row in bar: country = session.query(Country) \ .filter(Country.name == row['Name'], Country.code == row['Code']).first() if not country: country = Country(name=row['Name'], code=row['Code']) session.add(country) session.commit() except OSError as error: print("Error in import path: ", error) finally: session.close()
def delete(self, countryName: str): modelObject = Model.objects(countryName=countryName) modelObject.delete() return { "message": "Successfully deleted " + countryName }, 204