-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsxclient.py
More file actions
53 lines (48 loc) · 1.56 KB
/
dsxclient.py
File metadata and controls
53 lines (48 loc) · 1.56 KB
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
from baseclient import BaseClient
import urllib
class DsxClient(BaseClient):
def __init__(self, api_key, protocol=None, url=None):
self.protocol = 'https'
self.url = 'dsx.weather.com'
self.api_key = api_key
def search_locations(self, location):
# lol url path
a = ['x', 'v2', 'web', 'loc', 'en_US']
# bunch of random numbers?
b = ['1', '4', '5', '9', '11', '13', '19', '21', '1000', '1001', '1003']
c = ['us^', urllib.parse.quote(location)]
params = {
'api': self.api_key,
'format': 'json',
'pg': '0,10'
}
response = self._get(path=a+b+c, params=params)
try:
return response.json()
except:
print(response.text)
raise
def get_past_observations(self, datetime, numdays, loc_key):
path = ["wxd/v2/PastObsAvg", "en_US", datetime, numdays, loc_key]
params = {
'api': self.api_key,
'format': 'json'
}
response = self._get(path=path, params=params)
try:
return response.json()
except:
print(response.text)
raise
def get_astro(self, datetime, numdays, loc_key):
path = ['wxd/v2/Astro', 'en-US', datetime, numdays, loc_key]
params = {
'api': self.api_key,
'format': 'json'
}
response = self._get(path=path, params=params)
try:
return response.json()['AstroData']
except:
print(response.text)
raise