Added geolookup for station location
This commit is contained in:
parent
b4e7a5b1a1
commit
50e7ca7e25
|
@ -10,6 +10,7 @@ buildPythonApplication {
|
||||||
pillow
|
pillow
|
||||||
requests
|
requests
|
||||||
pytz
|
pytz
|
||||||
|
geopy
|
||||||
];
|
];
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
|
|
27
update.py
27
update.py
|
@ -10,7 +10,10 @@ from PIL import ImageDraw
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
from geopy.geocoders import Nominatim
|
||||||
|
|
||||||
FONT_SIZE = 40
|
FONT_SIZE = 40
|
||||||
|
FONT_SIZE_SMALL = 20
|
||||||
TEXT_COLOR = (255, 255, 255, 255)
|
TEXT_COLOR = (255, 255, 255, 255)
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,9 +69,25 @@ def main():
|
||||||
resp.json()['image'])
|
resp.json()['image'])
|
||||||
print(sat_img_url)
|
print(sat_img_url)
|
||||||
|
|
||||||
|
geolocator = Nominatim(
|
||||||
|
user_agent=
|
||||||
|
"satnogs-demo-display - https://forgejo.zenerdio.de/sebastian/satnogs-demo-display"
|
||||||
|
)
|
||||||
|
|
||||||
mode_desc = ob['transmitter_mode']
|
mode_desc = ob['transmitter_mode']
|
||||||
frequency = ob['observation_frequency'] / 1_000_000
|
frequency = ob['observation_frequency'] / 1_000_000
|
||||||
|
|
||||||
|
coord = "%f, %f" % (ob['station_lat'], ob['station_lng'])
|
||||||
|
address = geolocator.reverse(coord, exactly_one=True,
|
||||||
|
language="en").raw['address']
|
||||||
|
city = address.get('city', '')
|
||||||
|
country = address.get('country', '')
|
||||||
|
station_location = ""
|
||||||
|
if city != "":
|
||||||
|
station_location += "near " + city + " "
|
||||||
|
if country != "":
|
||||||
|
station_location += "in " + country
|
||||||
|
|
||||||
resp = requests.get(ob['waterfall'])
|
resp = requests.get(ob['waterfall'])
|
||||||
waterfall = Image.open(BytesIO(resp.content)).convert('RGBA')
|
waterfall = Image.open(BytesIO(resp.content)).convert('RGBA')
|
||||||
invert_back_white(waterfall)
|
invert_back_white(waterfall)
|
||||||
|
@ -98,8 +117,9 @@ def main():
|
||||||
station_name = ob['station_name']
|
station_name = ob['station_name']
|
||||||
if len(station_name) > 20:
|
if len(station_name) > 20:
|
||||||
station_name = station_name[:20] + "..."
|
station_name = station_name[:20] + "..."
|
||||||
infos = "Satellite: %s\nStation: %s\nMode: %s\nFrequency: %f MHz\nStart: %s\nEnd: %s" % (
|
infos = "Satellite: %s\nStation: %s\n%s\nMode: %s\nFrequency: %f MHz\nStart: %s\nEnd: %s" % (
|
||||||
sat_name, station_name, mode_desc, frequency, ob['start'], ob['end'])
|
sat_name, station_name, station_location, mode_desc, frequency,
|
||||||
|
ob['start'], ob['end'])
|
||||||
|
|
||||||
font = ImageFont.truetype("Montserrat-Regular.otf", FONT_SIZE)
|
font = ImageFont.truetype("Montserrat-Regular.otf", FONT_SIZE)
|
||||||
draw.text((water_width + 100, logo_h + 50), infos, TEXT_COLOR, font=font)
|
draw.text((water_width + 100, logo_h + 50), infos, TEXT_COLOR, font=font)
|
||||||
|
@ -109,6 +129,9 @@ def main():
|
||||||
if sat_img != None:
|
if sat_img != None:
|
||||||
img.paste(sat_img, (water_width + 100, 500))
|
img.paste(sat_img, (water_width + 100, 500))
|
||||||
|
|
||||||
|
font = ImageFont.truetype("Montserrat-Regular.otf", FONT_SIZE_SMALL)
|
||||||
|
draw.text((950, 1000), "Geocoding by Nominatim/OSM", TEXT_COLOR, font=font)
|
||||||
|
|
||||||
img.save('waterfall_tmp.png')
|
img.save('waterfall_tmp.png')
|
||||||
os.rename('waterfall_tmp.png', 'waterfall.png')
|
os.rename('waterfall_tmp.png', 'waterfall.png')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue