FR24 CSV import support complete
This commit is contained in:
parent
7f70993fdd
commit
a8cf3da745
@ -105,8 +105,10 @@ def manyPlanes(arguments):
|
||||
row['longitude'] = float(row['longitude'])
|
||||
if not 'altitude' in row.keys():
|
||||
row['altitude'] = arguments.altitude
|
||||
print('here')
|
||||
else:
|
||||
row['altitude'] = float(row['altitude'])
|
||||
print('there')
|
||||
if not 'capability' in row.keys():
|
||||
row['capability'] = arguments.capability
|
||||
if not 'typecode' in row.keys():
|
||||
@ -121,6 +123,7 @@ def manyPlanes(arguments):
|
||||
row['surface'] = arguments.surface
|
||||
logger.debug('Row from CSV: %s' % (row))
|
||||
modes = ModeS()
|
||||
print(row['altitude'])
|
||||
(df17_even, df17_odd) = modes.df17_pos_rep_encode(row['capability'], row['icao'], row['typecode'], row['surveillancestatus'], row['nicsupplementb'], row['altitude'], row['time'], row['latitude'], row['longitude'], row['surface'])
|
||||
|
||||
ppm = PPM()
|
||||
|
34
FR24csv.py
34
FR24csv.py
@ -17,6 +17,16 @@ def argParser():
|
||||
parser.add_argument('--csv', '--csvfile', '--in', '--input', action='store', type=str, dest='csvfile', help='The name of the FR24 CSV file', required=True)
|
||||
return parser.parse_args()
|
||||
|
||||
def reverseCSV(csvfile):
|
||||
"""Reverse a CSV. Returns a dictionary of the CSV"""
|
||||
data = []
|
||||
with open(csvfile, newline='') as csvfilein:
|
||||
reader = csv.DictReader(csvfilein, delimiter=',')
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
csvfilein.close()
|
||||
return reversed(data)
|
||||
|
||||
def main():
|
||||
global cfg
|
||||
cfg = configparser.ConfigParser()
|
||||
@ -27,19 +37,19 @@ def main():
|
||||
csvFilename = 'fr24.csv'
|
||||
|
||||
time = 0
|
||||
|
||||
#Need to reverse the FR24 CSV as it is in reverse order i.e. the most recent record is row 2 and the first ADS-B message of the flight is the last row in the CSV
|
||||
data = reverseCSV(arguments.csvfile)
|
||||
with open(csvFilename, 'w', newline='') as csvfileout:
|
||||
output = csv.writer(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||
output.writerow(['time', 'icao', 'latitude', 'longitude', 'altitude'])
|
||||
with open(arguments.csvfile, newline='') as csvfilein:
|
||||
reader = csv.DictReader(csvfilein, delimiter=',')
|
||||
for row in reader:
|
||||
if time == 0:
|
||||
time = int(row['Timestamp'])
|
||||
rowtime = int(row['Timestamp']) - time
|
||||
newrow = [rowtime, hex(arguments.icao), 'lat', 'long', row['Altitude']]
|
||||
output.writerow([newrow])
|
||||
print(newrow)
|
||||
fieldnames = ['timestamp', 'icao', 'latitude', 'longitude', 'altitude']
|
||||
output = csv.DictWriter(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames)
|
||||
output.writeheader()
|
||||
for row in data:
|
||||
if time == 0:
|
||||
time = int(row['Timestamp'])
|
||||
rowtime = int(row['Timestamp']) - time
|
||||
position = row['Position'].split(',')
|
||||
newrow = {'timestamp':rowtime, 'icao':hex(arguments.icao), 'latitude':position[0], 'longitude':position[1], 'altitude':row['Altitude']}
|
||||
output.writerow(newrow)
|
||||
csvfileout.close()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user