Skip to content

Commit 281c4ae

Browse files
committed
Minor changes:
*) simplified 'config.ini' parsing. *) added 'USER_AGENT' handling. *) added 'ATC_STREAM_URL' to the window title.
1 parent 7569388 commit 281c4ae

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

src/externals/Retro-ADSB-radar/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
FETCH_INTERVAL = 4
33
MIL_PREFIX_LIST = 7CF
44
TAR1090_URL = http://127.0.0.1:8080/data/aircraft.json
5+
USER_AGENT = Retro-ADSB-Radar
56
BLINK_MILITARY = true
67
VERBOSE = false
78

src/externals/Retro-ADSB-radar/config.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
import os, configparser
22

3-
#
4-
# Fix a line like 'key = value # some trailing comment\n'
5-
# into 'key = value\n'
6-
#
7-
def strip_trailing_comment (s):
8-
a = s.find ("#")
9-
b = s.find ("=")
10-
if a > 0 and a > b:
11-
s = s[:a].rstrip (" ") + "\n"
12-
return s
13-
14-
def get_lines (file):
15-
f = open (file, "rt")
16-
lines = f.readlines()
17-
lines2 = ""
18-
f.close()
19-
for l in lines:
20-
lines2 += strip_trailing_comment (l)
21-
return lines2
22-
233
#
244
# Configuration Loading
255
#
26-
config = configparser.ConfigParser (strict=False)
27-
286
script_dir = os.path.dirname (os.path.abspath(__file__)).replace ("\\", "/")
29-
config.read_string (get_lines(f"{script_dir}/config.ini"))
7+
8+
config = configparser.ConfigParser (strict = False, inline_comment_prefixes = ("#"))
9+
config.read (f"{script_dir}/config.ini")
3010

3111
#
3212
# General Settings
3313
#
3414
FETCH_INTERVAL = config.getint ("General", "FETCH_INTERVAL", fallback=10)
3515
MIL_PREFIX_LIST = [ prefix.strip() for prefix in config.get("General", "MIL_PREFIX_LIST", fallback="7CF").split(",") ]
3616
TAR1090_URL = config.get ("General", "TAR1090_URL", fallback="http://localhost/data/aircraft.json")
17+
USER_AGENT = config.get ("General", "USER_AGENT", fallback=None)
3718
BLINK_MILITARY = config.getboolean ("General", "BLINK_MILITARY", fallback=True)
3819
VERBOSE = config.getboolean ("General", "VERBOSE", fallback=False)
3920

src/externals/Retro-ADSB-radar/data_fetcher.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ def __init__ (self):
1616
def fetch_data (self) -> List [Aircraft]:
1717
"""Fetch aircraft from local tar1090"""
1818
try:
19-
if 0:
19+
if config.VERBOSE:
2020
print (f"Fetching aircraft data from {config.TAR1090_URL}...")
21-
response = requests.get (config.TAR1090_URL, timeout=10)
21+
if config.USER_AGENT:
22+
headers = { "User-Agent": config.USER_AGENT }
23+
else:
24+
headers = None # becomes default "python-requests/2.31.0"
25+
26+
response = requests.get (config.TAR1090_URL, timeout=10, headers=headers)
2227
response.raise_for_status()
2328
data = response.json()
2429
aircraft_list = []

src/externals/Retro-ADSB-radar/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ def main():
5656
# Display Setup
5757
#
5858
screen = pygame.display.set_mode ((config.SCREEN_WIDTH, config.SCREEN_HEIGHT), flags)
59-
pygame.display.set_caption (f"{config.AREA_NAME} ADS-B RADAR")
59+
60+
win_caption = f"ADS-B RADAR, {config.AREA_NAME}"
61+
if config.ATC_STREAM_URL:
62+
win_caption += f", qAudio: {config.ATC_STREAM_URL}"
63+
pygame.display.set_caption (win_caption)
64+
6065
clock = pygame.time.Clock()
6166
if config.BACKGROUND_PATH:
6267
background = utils.load_background (config.BACKGROUND_PATH)
@@ -233,6 +238,7 @@ def main():
233238
running = False
234239
last_mouse_move = time.time()
235240
pygame.mouse.set_visible (True)
241+
236242
elif event.type in (pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP):
237243
last_mouse_move = time.time()
238244
pygame.mouse.set_visible (True)

0 commit comments

Comments
 (0)