config_file_name = "forecastio.config" # warning: don't interrupt program using ctrl c, press enter instead to avoid file writing problems def get_api_key(): if os.path.isfile(config_file_name) and len(open("forecastio.config", "rb").read().splitlines()) > 0: return open("forecastio.config", "rb").read().splitlines()[0] else: raise Exception( "The configuration file '{0}' containing your API key is invalid or does not exist.".format( config_file_name ) ) d = DataUtility() weather_config = d.read_json_file("weather-data-collection.json") start_time = int( time.mktime( datetime.datetime.strptime(weather_config["meta"]["dateRange"]["start"], "%Y-%m-%dT00:00:00.000Z").timetuple() ) ) end_time = int( time.mktime( datetime.datetime.strptime(weather_config["meta"]["dateRange"]["end"], "%Y-%m-%dT00:00:00.000Z").timetuple() ) ) start_lat = weather_config["meta"]["geographicRange"]["upperLeft"]["latitude"]
import json from DataUtility import DataUtility d = DataUtility() weather_source = d.read_json_file('weather-data-collection.json') weatherData = weather_source["data"] temperatureData = [] windData = [] cloudCoverData = [] precipitationData = [] # goes through all Datapoints in the mixed weather-data-collection, # splits the Data into the different weatherSources and finally writes # them into different Data-Arrays for index, entry in enumerate(weatherData): # not every entry has every key included. so every key is checked first keyTemperature = "temperature" if keyTemperature in entry: temperatureEntry = {'latitude':entry["latitude"],'longitude':entry["longitude"],'temperature':entry["temperature"],'timestamp':entry["time"],"children": []} temperatureData.append(temperatureEntry) keyWindSpeed = "windSpeed" keyWindBearing = "windBearing" if keyWindSpeed and keyWindBearing in entry: windEntry = {'latitude':entry["latitude"],'longitude':entry["longitude"],'speed':entry["windSpeed"],'direction':entry["windBearing"],'timestamp':entry["time"],"children": []} windData.append(windEntry) keyCloudCover = "cloudCover" if keyCloudCover in entry: cloudCoverEntry = {'latitude':entry["latitude"],'longitude':entry["longitude"],'cloudCover':entry["cloudCover"],'timestamp':entry["time"],"children": []}
from DataUtility import DataUtility d = DataUtility() # Read an example CSV file csv_file = d.read_csv_file('example-data/test.csv') print csv_file # Access a specific row and key print csv_file[0]['author'] # Read an example XML file xml_file = d.read_xml_file('example-data/test.xml') print xml_file # Access a specific entry from the XML tree print xml_file['cities']['stadt']['stadt'][1]['name'] # Read an example JSON file json_file = d.read_json_file('example-data/test.json') print json_file # Access a specific entry from the JSON tree print json_file['globe']['radius'] # Write one of the dictionaries to a new JSON file d.write_json_file(csv_file, 'example-data/output.json')