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'])
|
row['longitude'] = float(row['longitude'])
|
||||||
if not 'altitude' in row.keys():
|
if not 'altitude' in row.keys():
|
||||||
row['altitude'] = arguments.altitude
|
row['altitude'] = arguments.altitude
|
||||||
|
print('here')
|
||||||
else:
|
else:
|
||||||
row['altitude'] = float(row['altitude'])
|
row['altitude'] = float(row['altitude'])
|
||||||
|
print('there')
|
||||||
if not 'capability' in row.keys():
|
if not 'capability' in row.keys():
|
||||||
row['capability'] = arguments.capability
|
row['capability'] = arguments.capability
|
||||||
if not 'typecode' in row.keys():
|
if not 'typecode' in row.keys():
|
||||||
@ -121,6 +123,7 @@ def manyPlanes(arguments):
|
|||||||
row['surface'] = arguments.surface
|
row['surface'] = arguments.surface
|
||||||
logger.debug('Row from CSV: %s' % (row))
|
logger.debug('Row from CSV: %s' % (row))
|
||||||
modes = ModeS()
|
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'])
|
(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()
|
ppm = PPM()
|
||||||
|
28
FR24csv.py
28
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)
|
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()
|
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():
|
def main():
|
||||||
global cfg
|
global cfg
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
@ -27,19 +37,19 @@ def main():
|
|||||||
csvFilename = 'fr24.csv'
|
csvFilename = 'fr24.csv'
|
||||||
|
|
||||||
time = 0
|
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:
|
with open(csvFilename, 'w', newline='') as csvfileout:
|
||||||
output = csv.writer(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
fieldnames = ['timestamp', 'icao', 'latitude', 'longitude', 'altitude']
|
||||||
output.writerow(['time', 'icao', 'latitude', 'longitude', 'altitude'])
|
output = csv.DictWriter(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames)
|
||||||
with open(arguments.csvfile, newline='') as csvfilein:
|
output.writeheader()
|
||||||
reader = csv.DictReader(csvfilein, delimiter=',')
|
for row in data:
|
||||||
for row in reader:
|
|
||||||
if time == 0:
|
if time == 0:
|
||||||
time = int(row['Timestamp'])
|
time = int(row['Timestamp'])
|
||||||
rowtime = int(row['Timestamp']) - time
|
rowtime = int(row['Timestamp']) - time
|
||||||
newrow = [rowtime, hex(arguments.icao), 'lat', 'long', row['Altitude']]
|
position = row['Position'].split(',')
|
||||||
output.writerow([newrow])
|
newrow = {'timestamp':rowtime, 'icao':hex(arguments.icao), 'latitude':position[0], 'longitude':position[1], 'altitude':row['Altitude']}
|
||||||
print(newrow)
|
output.writerow(newrow)
|
||||||
csvfileout.close()
|
csvfileout.close()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user