-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdatasource.py
47 lines (32 loc) · 1.08 KB
/
datasource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import configparser
import flightdata
import screenshot
class Error(Exception):
pass
DRIVERS = {
'dump1090': dict(
data=flightdata.Dump1090DataParser,
map=screenshot.Dump1090Display),
'virtualradarserver': dict(
data=flightdata.VRSDataParser,
map=screenshot.VRSDisplay)
}
DEFAULT_DRIVER = 'dump1090'
def get_driver():
driver = DRIVERS.get(g_driver, None)
if not driver:
raise Error('Unknown driver: {}. Valid drivers are {}'.format(
g_driver, ', '.join(DRIVERS.keys())))
return driver
def get_map_source():
return get_driver()['map'](g_map_url)
def get_data_source():
return flightdata.FlightData(
data_url=g_data_url,
parser=get_driver()['data']())
parser = configparser.ConfigParser()
parser.read('config.ini')
abovetustin = parser['abovetustin']
g_driver = abovetustin.get('driver', DEFAULT_DRIVER)
g_data_url = parser.get('abovetustin', 'data_url')
g_map_url = parser.get('abovetustin', 'map_url')