Commit 4214196b authored by markus's avatar markus

Rotate image if northbound

parent 0a724d09
......@@ -34,11 +34,13 @@ def generate_wav(audio):
shutil.rmtree(dirpath)
return wav
def colorize_noaa_image(wav):
def process_noaa_image(wav, northbound = False):
with tempfile.NamedTemporaryFile() as tmp_wav:
tmp_wav.write(wav)
dirpath = tempfile.mkdtemp()
subprocess.run(["wxtoimg", "-e", "HVC", tmp_wav.name, f"{dirpath}/result.png"])
subprocess.run(["wxtoimg", "-e", "HVC"]
+ (["-N"] if northbound else [])
+ [tmp_wav.name, f"{dirpath}/result.png"])
with open(f"{dirpath}/result.png", "rb") as tmp_result:
result = tmp_result.read()
shutil.rmtree(dirpath)
......@@ -48,13 +50,14 @@ def process_observation(observation, observation_data):
waterfall_image = download(observation_data["waterfall_url"])
data_images = [download(x) for x in observation_data["data_image_urls"]]
audio = download(observation_data["audio_url"])
northbound = abs(180 - observation_data["rise"]) < abs(180 - observation_data["set"])
if observation_data["satellite_name"].startswith("NOAA"):
logger.info("Generating wav")
wav = generate_wav(audio)
logger.info("Done generating wav")
logger.info("Generating colorized image")
colorized_image = colorize_noaa_image(wav)
colorized_image = process_noaa_image(wav, northbound)
logger.info("Done colorizing image")
twitter_client.handle_observation(observation, observation_data, waterfall_image, [colorized_image])
else:
......
......@@ -46,6 +46,8 @@ def get_observation_data(satnogs_address, observation):
audio_url = re.search(f"data-audio=\"(/media/data_obs/{observation}/(.*?))\"", page).group(1)
satellite_id = re.search("<a href=\"#\" data-toggle=\"modal\" data-target=\"#SatelliteModal\" data-id=\"(\d+)\">", page).group(1)
satellite_name = re.search(f"\s+{satellite_id}\s+-\s+(.*?)</a>", page).group(1).strip()[:-2] # remove magic \n
rise = float(re.search("<div class=\"green_circle\"></div>.*?((\d+)\.(\d+))", page).group(1))
set_ = float(re.search("<div class=\"red_circle\"></div>.*?((\d+)\.(\d+))", page).group(1))
data_timeframe_start = re.search(f"data-timeframe-start=\"(.*?)\"", page).group(1).strip()
data_timeframe_end = re.search(f"data-timeframe-end=\"(.*?)\"", page).group(1).strip()
......@@ -55,6 +57,8 @@ def get_observation_data(satnogs_address, observation):
"audio_url": f"{satnogs_address}{audio_url}",
"satellite_id": satellite_id,
"satellite_name": satellite_name,
"rise": rise,
"set": set_,
"data_timeframe_start": data_timeframe_start,
"data_timeframe_end": data_timeframe_end,
"url": url,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment