-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvatsimdata.py
59 lines (55 loc) · 2.1 KB
/
vatsimdata.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
from aircraft import Aircraft
from urllib.request import urlopen
import json
import sys
try:
url = 'https://data.vatsim.net/v3/vatsim-data.json'
# Store the responses
response = urlopen(url)
response2 = open('airlines.json', 'r')
# Read the JSON's
data = json.loads(response.read())
data2 = json.loads(response2.read())
except:
print("\nUnable to fetch json data.")
sys.exit(1)
# Define data extraction
def get_data():
pilots = data['pilots']
phonetic = data2['phonetic']
# Store the user input
print("\nPlease select the type of strips to collect and print: ")
selection = input("Arrival or Departure? (a/d): ")
if selection == "a":
x = 'arrival'
else:
x = 'departure'
# Prepare an empty list
strip = []
for pilot in pilots:
if pilot['flight_plan'] == None:
continue
# Try to get phonetic callsign from the airlines.json and add it to a variable
# If it's not in the database, then add an empty string
if pilot['flight_plan'][x] == "EFHK":
try:
y = phonetic[pilot['callsign'][0:3]]
except:
y = ""
# Fill the strip list with necessary data
strip.append(Aircraft(pilot['callsign'],
y,
pilot['transponder'],
pilot['flight_plan']['aircraft'],
pilot['flight_plan']['remarks'],
pilot['flight_plan']['deptime'],
pilot['flight_plan']['altitude'],
"sidstar",
"rwy",
pilot['flight_plan']['departure'],
pilot['flight_plan']['arrival'],
pilot['flight_plan']['enroute_time'],
pilot['flight_plan']['route'],
pilot['flight_plan']['flight_rules']
))
return strip