Initial commit

This commit is contained in:
Sebastian 2018-12-24 12:16:47 +01:00
commit 13d6e94dba
5 changed files with 79 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
virtenv
waterfall.png

BIN
Montserrat-Regular.otf Normal file

Binary file not shown.

7
requirements.txt Normal file
View File

@ -0,0 +1,7 @@
certifi==2018.11.29
chardet==3.0.4
idna==2.8
Pillow==5.3.0
pytz==2018.7
requests==2.21.0
urllib3==1.24.1

BIN
satnogs-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

70
update.py Normal file
View File

@ -0,0 +1,70 @@
#!/bin/env python3
import os
import requests
import pytz
from datetime import datetime, timedelta
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from io import BytesIO
FONT_SIZE = 40
TEXT_COLOR = (0, 0, 0)
def main():
now = datetime.now(pytz.utc)
earlier = now - timedelta(hours=1)
params = {'start' : earlier.isoformat(), 'end' : now.isoformat() }
resp = requests.get('https://network.satnogs.org/api/data/', params=params)
obs = resp.json()
obs = reversed(sorted(obs, key=lambda x: x['end']))
for ob in obs:
if ob['waterfall'] != None:
break
if ob['waterfall'] == None:
print("No waterfall found")
return
resp = requests.get('https://db.satnogs.org/api/satellites/%s/' % ob['norad_cat_id'])
sat_name = resp.json()['name']
resp = requests.get(ob['waterfall'])
waterfall = Image.open(BytesIO(resp.content))
width, height = waterfall.size
new_height = 1024
new_width = int(new_height * width / height)
waterfall = waterfall.resize((new_width, new_height), Image.ANTIALIAS)
logo = Image.open("satnogs-logo.png").convert(waterfall.mode)
logo_w, logo_h = logo.size
img = Image.new(waterfall.mode, (1280,1024))
draw = ImageDraw.Draw(img)
draw.rectangle((0, 0, 1280, 1024), fill=(255, 255, 255, 255))
infos = "Satellite: %s\nStation: %s\nStart: %s\nEnd: %s" % (sat_name, ob['station_name'], ob['start'], ob['end'])
font = ImageFont.truetype("Montserrat-Regular.otf", FONT_SIZE)
draw.text((new_width + 100, logo_h+50),
infos,
TEXT_COLOR,
font=font)
img.paste(waterfall, (0, 0))
img.paste(logo, (new_width + 100, 20))
img.save('waterfall_tmp.png')
os.rename('waterfall_tmp.png', 'waterfall.png')
if __name__ == '__main__':
main()