-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairports_export.py
38 lines (29 loc) · 940 Bytes
/
airports_export.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
import json
import pickle
import re
airports = r'C:\Users\ujasv\OneDrive\Desktop\codes\cirrostrats-backend\all_US_airports_dict.pkl'
with open(airports, 'rb') as f:
x = pickle.load(f)
xx = []
for a,b in x.items():
US_state = a
cities = b[1]
for each_city in cities:
xx.append(each_city)
airport_dict = {}
for i in xx:
first_dash_index = re.search(r'-', i).start()
# Splitting the string by the first dash
first_part = i[:first_dash_index][:-1]
second_part = i[first_dash_index + 1:][1:]
airport_dict.update({first_part:second_part})
airport_list = []
for airport_id, airport_name in airport_dict.items():
airport_data = {
'id': airport_id,
'name': airport_name,
'code': airport_id # Assuming the code is the same as the airport ID
}
airport_list.append(airport_data)
with open('airports_dump.json','w') as f:
json.dump(airport_dict,f)