-
Notifications
You must be signed in to change notification settings - Fork 11
/
get_current_nasr_url.py
executable file
·57 lines (48 loc) · 1.35 KB
/
get_current_nasr_url.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
#!/usr/bin/python3
import json
from urllib.request import Request, urlopen
import errno, sys
# The URL to get data from
# "edition=next" to get the upcoming edition
url="https://soa.smext.faa.gov/apra/nfdc/nasr/chart?edition=current"
# Some sample JSON for testing with
sample_json="""
{
"status": {
"code": 200,
"message": "OK"
},
"edition": [
{
"editionName": "CURRENT",
"format": "ZIP",
"editionDate": "11/09/2017",
"editionNumber": 12
}
]
}
"""
def get_jsonparsed_data(url):
# Build the request
request = Request(url)
request.add_header('accept', 'application/json')
# Get the json
try:
json_response = urlopen(request).read().decode("utf-8")
except:
print("Error getting NASR information from {}".format(url))
return None
# Parse it
response_dictionary = (json.loads(json_response))
# Return the dictionary
return response_dictionary
# Get the JSON data and return a dictionary of values from it
response_dictionary = get_jsonparsed_data(url)
# Print some of the values
if response_dictionary:
edition_date = response_dictionary['edition'][0]['editionDate']
edition_url = response_dictionary['edition'][0]['product']['url']
#print(edition_date)
print(edition_url)
else:
sys.exit(1)