| importrequests |
| fromrequests.authimportHTTPBasicAuth |
| importpprint |
| |
| importpandasaspd |
| |
| df=pd.read_excel('California.xlsx') |
| # print(df.head()) |
| |
| base_url='http://api.meteomatics.com/' |
| time='2020-10-03T18:00:00Z/' |
| params='t_2m:C,prob_precip_12h:p,is_rain_1h:idx,wind_speed_10m:ms,wind_dir_700hPa:d,land_usage:idx,soil_type:idx,elevation:m/' |
| geolocation='-8.5,22.80/' |
| _type='json' |
| |
| df['temp'] =0 |
| df['precip'] =0 |
| df['rain'] =0 |
| df['wind_speed'] =0 |
| df['wind_dir'] =0 |
| df['land_usage'] =0 |
| df['soil_type'] =0 |
| df['elevation'] =0 |
| |
| forindexinrange(1050): |
| _time=str(df.loc[index, "acq_date"]).split(' ')[0] +'T'+ ( |
| '0'+str(df.loc[index, 'acq_time'])[:-2] iflen(str(df.loc[index, 'acq_time'])[:-2]) ==1elsestr( |
| df.loc[index, 'acq_time'])[:-2]) +':'+str(df.loc[index, 'acq_time'])[-2:] +':00Z/' |
| _geo=str(df.loc[index, "latitude"]) +','+str(df.loc[index, "longitude"]) +'/' |
| url=base_url+_time+params+_geo+_type |
| |
| print(url) |
| |
| try: |
| response=requests.get(url, |
| # auth=HTTPBasicAuth('servarevitas_jha', 'i3fgRtU4KC8lE')) |
| auth=HTTPBasicAuth('siemens_bhalla', 'CuNgd4ie8AH3E')) |
| |
| df.loc[index, 'temp'] =response.json()['data'][0]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'precip'] =response.json()['data'][1]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'rain'] =response.json()['data'][2]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'wind_speed'] =response.json()['data'][3]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'wind_dir'] =response.json()['data'][4]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'land_usage'] =response.json()['data'][5]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'soil_type'] =response.json()['data'][6]['coordinates'][0]['dates'][0]['value'] |
| df.loc[index, 'elevation'] =response.json()['data'][7]['coordinates'][0]['dates'][0]['value'] |
| except: |
| continue |
| |
| df.to_csv('cali_baland.csv', index=False) |