-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfaker_airline.py
47 lines (34 loc) · 1.29 KB
/
faker_airline.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
# https://pypi.org/project/faker_airtravel/
# pip install faker_airtravel
import csv
from faker import Faker
from faker_airtravel import AirTravelProvider
fake = Faker()
fake.add_provider(AirTravelProvider)
csv_file = open('faker_airports.csv', 'w')
csv_file.write('airport|iata|icao|city|state|country\n')
num_records = 100000
iata_list = []
for i in range(0, num_records):
airline = fake.flight()
print(airline)
origin = airline['origin']
destination = airline['destination']
iata = origin['iata']
if iata not in iata_list:
iata_list.append(iata)
airport = origin['airport']
icao = origin['icao']
city = origin['city']
state = origin['state']
country = origin['country'].title()
csv_file.write(airport + '|' + iata + '|' + icao + '|' + city + '|' + state + '|' + country + '\n')
iata = destination['iata']
if iata not in iata_list:
iata_list.append(iata)
airport = destination['airport']
icao = destination['icao']
city = destination['city']
state = destination['state']
country = destination['country'].title()
csv_file.write(airport + '|' + iata + '|' + icao + '|' + city + '|' + state + '|' + country + '\n')