Rearrange json DB stuff so it can work with CSV input.
This commit is contained in:
parent
ca57fb27f0
commit
158a8298fc
4 changed files with 31197 additions and 15 deletions
31
tools/vrs-to-csv.py
Executable file
31
tools/vrs-to-csv.py
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
#
|
||||
# Converts a Virtual Radar Server BasicAircraftLookup.sqb database
|
||||
# to a CSV file suitable for feeding to csv-to-json.py
|
||||
#
|
||||
|
||||
import sqlite3, csv, sys
|
||||
from contextlib import closing
|
||||
|
||||
def extract(dbfile):
|
||||
writer = csv.DictWriter(sys.stdout,
|
||||
fieldnames=['icao24', 'r', 't'])
|
||||
writer.writeheader()
|
||||
with closing(sqlite3.connect(dbfile)) as db:
|
||||
with closing(db.execute('SELECT a.Icao, a.Registration, m.Icao FROM Aircraft a, Model m WHERE a.ModelID = m.ModelID')) as c:
|
||||
for icao24, reg, icaotype in c:
|
||||
writer.writerow({
|
||||
'icao24': icao24,
|
||||
'r': reg,
|
||||
't': icaotype
|
||||
})
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print >>sys.stderr, 'Reads a VRS sqlite database and writes a CSV to stdout'
|
||||
print >>sys.stderr, 'Syntax: %s <path to BasicAircraftLookup.sqb>' % sys.argv[0]
|
||||
sys.exit(1)
|
||||
else:
|
||||
extract(sys.argv[1])
|
||||
sys.exit(0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue