-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_requests.py
More file actions
49 lines (38 loc) · 1.47 KB
/
make_requests.py
File metadata and controls
49 lines (38 loc) · 1.47 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
import urllib.request
import urllib.parse
import json
import ssl
def api_getter(key: str, url: str):
offset_counter = 1
file_counter = 0
# file_counter += 1
# offset_counter += 1000
# ssl._create_default_https_context = ssl._create_unverified_context
api_url = url + 'offset=' + str(offset_counter)
headers = {'token': key}
r = urllib.request.Request(api_url, headers=headers)
return r
def load_json(r: str, file_counter: int):
while file_counter < 39:
file_name = './location_' + str(file_counter) + '.json'
with urllib.request.urlopen(r) as f:
data = json.load(f)
return data
# with open(file_name, 'w') as handler:
# json.dump(data, handler)
# api_getter('YPfkbkEbwdPHBHLxeFSIJQGPzjLUJYIB', 'https://www.ncdc.noaa.gov/cdo-web/api/v2/')
# import urllib.request
# import urllib.parse
# import json
# api_getter('https://www.ncdc.noaa.gov/cdo-web/api/v2/',
# 'YPfkbkEbwdPHBHLxeFSIJQGPzjLUJYIB')
# url = 'https://www.ncdc.noaa.gov/cdo-web/api/v2/locations?location&limt=1000&' + 'offset=' + str(offset_counter)
# headers = {'token': '#my token'}
# req = urllib.request.Request(url, headers=headers)
# file_name = './location_' + str(file_counter) + '.json'
# with urllib.request.urlopen(req) as f:
# data = json.load(f)
# with open(file_name, 'w') as handler:
# json.dump(data, handler)
# file_counter += 1
# offset_counter += 1000