from datetime import datetime import requests import os import joblib import pandas as pd import json def get_weather_by_date(date): return requests.get(f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/helsinki/{date}?unitGroup=metric&include=days&key=J7TT2WGMUNNHD8JBEDXAJJXB2&contentType=json').json() def get_weather_df(data): col_names = [ 'name', 'datetime', 'tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'snowdepth', 'windgust', 'windspeed', 'winddir', 'sealevelpressure', 'cloudcover', 'visibility', 'solarradiation', 'solarenergy', 'uvindex', 'conditions' ] new_data = pd.DataFrame( data, columns=col_names ) new_data.datetime = new_data.datetime.apply(timestamp_2_time1) #new_data.rename(columes={'pressure':'sealevelpressure'}) return new_data def timestamp_2_time1(x): dt_obj = datetime.strptime(str(x), '%Y-%m-%d') dt_obj = dt_obj.timestamp() * 1000 return int(dt_obj) def timestamp_2_time(x): dt_obj = datetime.strptime(str(x), '%m/%d/%Y') dt_obj = dt_obj.timestamp() * 1000 return int(dt_obj)