File size: 1,426 Bytes
84a1a7d
 
 
 
 
 
 
 
 
 
8e7dace
a81da8d
84a1a7d
 
 
 
ad4878b
 
84a1a7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad4878b
84a1a7d
 
 
 
 
 
 
 
ad4878b
 
84a1a7d
 
 
 
ad4878b
 
84a1a7d
 
 
 
 
 
 
 
 
 
ad4878b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)