parent
6a9cf210bb
commit
46a3ca9dd2
@ -1,57 +1,57 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Will take a FR24 CSV and make a ADSB_Encoder CSV
|
# Will take a FR24 CSV and make a ADSB_Encoder CSV
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
def auto_int(x):
|
def auto_int(x):
|
||||||
"""Parses HEX into for argParser"""
|
"""Parses HEX into for argParser"""
|
||||||
return int(x, 0)
|
return int(x, 0)
|
||||||
|
|
||||||
def argParser():
|
def argParser():
|
||||||
description = 'This script will take a FR24 CSV file and convert it into a format for FR24csv.py'
|
description = 'This script will take a FR24 CSV file and convert it into a format for FR24csv.py'
|
||||||
parser = argparse.ArgumentParser(description=description)
|
parser = argparse.ArgumentParser(description=description)
|
||||||
parser.add_argument('-i', '--icao', action='store', type=auto_int, dest='icao', default=cfg.get('plane', 'icao'), help='The ICAO number for the plane in hex. Ensure the ICAO is prefixed with \'0x\' to ensure this is parsed as a hex number. This is 24 bits long. Default: %(default)s')
|
parser.add_argument('-i', '--icao', action='store', type=auto_int, dest='icao', default=cfg.get('plane', 'icao'), help='The ICAO number for the plane in hex. Ensure the ICAO is prefixed with \'0x\' to ensure this is parsed as a hex number. This is 24 bits long. Default: %(default)s')
|
||||||
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):
|
def reverseCSV(csvfile):
|
||||||
"""Reverse a CSV. Returns a dictionary of the CSV"""
|
"""Reverse a CSV. Returns a dictionary of the CSV"""
|
||||||
data = []
|
data = []
|
||||||
with open(csvfile, newline='') as csvfilein:
|
with open(csvfile, newline='') as csvfilein:
|
||||||
reader = csv.DictReader(csvfilein, delimiter=',')
|
reader = csv.DictReader(csvfilein, delimiter=',')
|
||||||
for row in reader:
|
for row in reader:
|
||||||
data.append(row)
|
data.append(row)
|
||||||
csvfilein.close()
|
csvfilein.close()
|
||||||
return reversed(data)
|
return reversed(data)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global cfg
|
global cfg
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg.read('config.cfg')
|
cfg.read('config.cfg')
|
||||||
|
|
||||||
arguments = argParser()
|
arguments = argParser()
|
||||||
|
|
||||||
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
|
#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)
|
data = reverseCSV(arguments.csvfile)
|
||||||
with open(csvFilename, 'w', newline='') as csvfileout:
|
with open(csvFilename, 'w', newline='') as csvfileout:
|
||||||
fieldnames = ['timestamp', 'icao', 'latitude', 'longitude', 'altitude']
|
fieldnames = ['timestamp', 'icao', 'latitude', 'longitude', 'altitude']
|
||||||
output = csv.DictWriter(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames)
|
output = csv.DictWriter(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames)
|
||||||
output.writeheader()
|
output.writeheader()
|
||||||
for row in data:
|
for row in data:
|
||||||
if time == 0:
|
if time == 0:
|
||||||
time = int(row['Timestamp'])
|
time = int(row['Timestamp'])
|
||||||
rowtime = int(row['Timestamp']) - time
|
rowtime = int(row['Timestamp']) - time
|
||||||
position = row['Position'].split(',')
|
position = row['Position'].split(',')
|
||||||
newrow = {'timestamp':rowtime, 'icao':hex(arguments.icao), 'latitude':position[0], 'longitude':position[1], 'altitude':row['Altitude']}
|
newrow = {'timestamp':rowtime, 'icao':hex(arguments.icao), 'latitude':position[0], 'longitude':position[1], 'altitude':row['Altitude']}
|
||||||
output.writerow(newrow)
|
output.writerow(newrow)
|
||||||
csvfileout.close()
|
csvfileout.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in new issue