-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather_api.py
89 lines (61 loc) · 2.15 KB
/
weather_api.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
configuration = swagger_client.Configuration()
configuration.api_key['key'] = '6eb9d101698a47a49db72950230706'
api_instance = swagger_client.APIsApi(swagger_client.ApiClient(configuration))
q = 'VIT Chennai'
dt = '2023-07-06'
try:
# Astronomy API
api_response = api_instance.astronomy(q, dt)
#pprint(api_response)
except ApiException as e:
print("Exception when calling APIsApi->astronomy: %s\n" % e)
configuration = swagger_client.Configuration()
configuration.api_key['key'] = '6eb9d101698a47a49db72950230706'
api_instance = swagger_client.APIsApi(swagger_client.ApiClient(configuration))
q = 'VIT Chennai'
days = 56
dt = '2023-08-08'
unixdt = 56
hour = 56
lang = 'lang_example'
try:
# Forecast API
api_response = api_instance.forecast_weather(q, days, dt=dt, unixdt=unixdt, hour=hour, lang=lang)
x = api_response.location
pprint(x)
except ApiException as e:
print("Exception when calling APIsApi->forecast_weather: %s\n" % e)
try:
geeky_file = open('data/details.txt', 'wt')
geeky_file.write(str(x))
geeky_file.close()
except:
print("Unable to write to file")
configuration = swagger_client.Configuration()
configuration.api_key['key'] = '6eb9d101698a47a49db72950230706'
api_instance = swagger_client.APIsApi(swagger_client.ApiClient(configuration))
q = 'VIT Chennai'
dt = '2023-08-08'
lang = 'lang_example'
try:
# Future API
api_response = api_instance.future_weather(q, dt=dt, lang=lang)
#pprint(api_response)
except ApiException as e:
print("Exception when calling APIsApi->future_weather: %s\n" % e)
configuration = swagger_client.Configuration()
configuration.api_key['key'] = '6eb9d101698a47a49db72950230706'
api_instance = swagger_client.APIsApi(swagger_client.ApiClient(configuration))
q = 'vit chennai'
lang = 'lang_example'
try:
# Realtime API
api_response = api_instance.realtime_weather(q, lang=lang)
# pprint(api_response)
except ApiException as e:
print("Exception when calling APIsApi->realtime_weather: %s\n" % e)