datetime.now().strftime(Common_DateTime_Format)) # Iterate over Icharm csv file download links and push date to DB for station_id, url in Links.items(): # Load the .csv to a Dataframe df = pd.read_csv(url, header=None, names=['year', 'month', 'day', 'hour', 'value']) df['timestamp'] = df[['year', 'month', 'day', 'hour']].apply(build_timestamp, raw=True, axis=1) # IF station does not exist in the database create one with given station configs details. station_info = get_station_info(station_id) station_details_in_db = mysql_adapter.get_station({ 'stationId': station_info['stationId'], 'name': station_info['name'] }) if station_details_in_db is None: print( "Station: {stationId: %s, name: %s} does not exist in the DB. Creating station in the DB..." % (station_info['stationId'], station_info['name'])) station_meta_list = station_info['station_meta'] station_meta_list.insert(0, Station.CUrW) row_count = mysql_adapter.create_station(station_meta_list) if row_count > 0: print("Created new station: ", station_meta_list) else: print("Unable to create new station: ", station_meta_list) continue
'station': '', 'variable': '', 'unit': '', 'type': '', 'source': '', 'name': '', } adapter = MySQLAdapter(host=MYSQL_HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, db=MYSQL_DB) for station in stations: print('station:', station) # Check whether station exists is_station_exists = adapter.get_station({'name': station['name']}) if is_station_exists is None: print('Station %s does not exists.', station['name']) if 'station_meta' in station and 'station_type' in station: station_meta = station['station_meta'] station_meta.insert(0, Station.getType(station['station_type'])) row_count = adapter.create_station(station_meta) if row_count > 0: print('Created new station %s', station_meta) is_station_exists = adapter.get_station( {'name': station['name']}) else: print("Unable to create station %s", station_meta) continue else: