Merge pull request #434 from ArjanOnwezen/make-airlines.db

new airlines_db
This commit is contained in:
Erwin Ried 2021-11-23 10:38:10 +01:00 committed by GitHub
commit 16923717d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 5597 additions and 6280 deletions

View File

@ -130,6 +130,7 @@ ADSBRxDetailsView::ADSBRxDetailsView(
{
char file_buffer[32] { 0 };
bool found = false;
int number_of_airlines = 0;
std::string airline_code;
size_t c;
@ -153,7 +154,8 @@ ADSBRxDetailsView::ADSBRxDetailsView(
// Try getting the airline's name from airlines.db
auto result = db_file.open("ADSB/airlines.db");
if (!result.is_valid()) {
// Search for 3-letter code in 0x0000~0x2000
// Search for 3-letter code
number_of_airlines = (db_file.size() / 68); // determine number of airlines in file
airline_code = entry_copy.callsign.substr(0, 3);
c = 0;
do {
@ -164,10 +166,10 @@ ADSBRxDetailsView::ADSBRxDetailsView(
found = true;
else
c++;
} while (!found);
} while (!found && (c < number_of_airlines));
if (found) {
db_file.seek(0x2000 + (c << 6));
db_file.seek((number_of_airlines * 4) + (c << 6)); // seek starting after index
db_file.read(file_buffer, 32);
text_airline.set(file_buffer);
db_file.read(file_buffer, 32);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.bountysource.com/
HostUrl=https://github-repository-files.githubusercontent.com/251043704/4747359?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211011%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211011T232519Z&X-Amz-Expires=300&X-Amz-Signature=25180babeea757c128d1a995735486006e018abe6941ab5493597d194dc7b994&X-Amz-SignedHeaders=host&actor_id=21973866&key_id=0&repo_id=251043704&response-content-disposition=attachment%3Bfilename%3Dairlines.csv.txt&response-content-type=text%2Fplain

View File

@ -1,42 +0,0 @@
#!/usr/bin/env python
# Copyright (C) 2017 Furrtek
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
import sys
import struct
outfile = open("airlines.db", "w")
# Download airlines.txt from http://xdeco.org/?page_id=30
lines = [line.rstrip('\n') for line in open('../../sdcard/ADSB/airlines.csv.txt', 'r')]
n = 0
for line in lines:
if line:
nd = line.find('(')
if (nd == -1):
nd = None
else:
nd -= 1
nline = line[4:7] + '\0' + line[10:nd] + '\0'
print nline
b = bytearray(nline)
pad_len = 32 - len(b)
b += "\0" * pad_len
outfile.write(b)

View File

@ -0,0 +1,7 @@
# Make airlines.db
Licensed under GNU GPL v3 (license)[../../../LICENSE]
USAGE:
- Copy file from: https://raw.githubusercontent.com/kx1t/planefence-airlinecodes/main/airlinecodes.txt
- Run Python 3 script: `./make_airlines_db.py`

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
#!/usr/bin/env python3
# Copyright (C) 2021 ArjanOnwezen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
# -------------------------------------------------------------------------------------
# Create airline.db, used for ADS-B receiver application, using
# https://raw.githubusercontent.com/kx1t/planefence-airlinecodes/main/airlinecodes.txt
# as a source.
# -------------------------------------------------------------------------------------
import csv
import unicodedata
icao_codes=bytearray()
airlines_countries=bytearray()
row_count=0
database=open("airlines.db", "wb")
with open('airlinecodes.txt', 'rt') as csv_file:
sorted_lines=sorted(csv_file.readlines())
for row in csv.reader(sorted_lines, quotechar='"', delimiter=',', quoting=csv.QUOTE_ALL, skipinitialspace=True):
icao_code=row[0]
# Normalize some unicode characters
airline=unicodedata.normalize('NFKD', row[1][:32]).encode('ascii', 'ignore')
country=unicodedata.normalize('NFKD', row[3][:32]).encode('ascii', 'ignore')
if len(icao_code) == 3 :
airline_padding=bytearray()
country_padding=bytearray()
print(icao_code,' - ', airline,' - ', country)
icao_codes=icao_codes+bytearray(icao_code+'\0', encoding='ascii')
airline_padding=bytearray('\0' * (32 - len(airline)), encoding='ascii')
country_padding=bytearray('\0' * (32 - len(country)), encoding='ascii')
airlines_countries=airlines_countries+bytearray(airline+airline_padding+country+country_padding)
row_count+=1
database.write(icao_codes+airlines_countries)
print("Total of", row_count, "ICAO codes stored in database")

BIN
sdcard/ADSB/airlines.db Normal file → Executable file

Binary file not shown.