Debian Codegraph @

tools/vrs-to-csv.py

raw symbols SCIP
1 #!/usr/bin/env python2
2
3 #
4 # Converts a Virtual Radar Server BasicAircraftLookup.sqb database
5 # to a CSV file suitable for feeding to csv-to-json.py
6 #
7
8 import sqlite3, csv, sys
9 from contextlib import closing
10
11 def extract(dbfile):
12 writer = csv.DictWriter(sys.stdout,
13 fieldnames=['icao24', 'r', 't'])
14 writer.writeheader()
15 with closing(sqlite3.connect(dbfile)) as db:
16 with closing(db.execute('SELECT a.Icao, a.Registration, m.Icao FROM Aircraft a, Model m WHERE a.ModelID = m.ModelID')) as c:
17 for icao24, reg, icaotype in c:
18 writer.writerow({
19 'icao24': icao24,
20 'r': reg,
21 't': icaotype
22 })
23
24 if __name__ == '__main__':
25 if len(sys.argv) < 2:
26 print >>sys.stderr, 'Reads a VRS sqlite database and writes a CSV to stdout'
27 print >>sys.stderr, 'Syntax: %s <path to BasicAircraftLookup.sqb>' % sys.argv[0]
28 sys.exit(1)
29 else:
30 extract(sys.argv[1])
31 sys.exit(0)