fix(helioviewer): getClosestImage returns a time format that the takescreenshot-api doesn't like, so convert it to ISO-8601 first.
This commit is contained in:
+12
-8
@@ -54,7 +54,7 @@ def pick(needle):
|
||||
in (" ".join(s[1]) + " " + s[2]).lower().replace("_", " ")
|
||||
]
|
||||
if not hits:
|
||||
sys.exit(f"keine Datenquelle passt auf {needle!r} (siehe --list)")
|
||||
sys.exit(f"no data source matches {needle!r} (see --list)")
|
||||
return hits[0]
|
||||
|
||||
|
||||
@@ -68,18 +68,23 @@ def main():
|
||||
what = sys.argv[2] if len(sys.argv) > 2 else "continuum"
|
||||
|
||||
sid, path, nick = pick(what)
|
||||
print(f"Quelle: [{sid}] {'/'.join(path)} ({nick})")
|
||||
print(f"Source: [{sid}] {'/'.join(path)} ({nick})")
|
||||
|
||||
# Welches Bild liegt dem Wunschzeitpunkt am naechsten? Wichtig:
|
||||
# Helioviewer liefert IMMER etwas, auch wenn es Stunden daneben liegt.
|
||||
_, raw = call("getClosestImage", date=date, sourceId=sid)
|
||||
meta = json.loads(raw)
|
||||
print(f"angefragt: {date}\ngeliefert: {meta['date']}")
|
||||
print(f"requested: {date}\ndelivered: {meta['date']}")
|
||||
|
||||
# getClosestImage liefert "YYYY-MM-DD HH:MM:SS" (Leerzeichen, kein
|
||||
# Zeitzonen-Suffix). takeScreenshot verlangt dagegen ISO 8601 mit "T"
|
||||
# und "Z", sonst antwortet die API mit HTTP 400.
|
||||
shot_date = meta["date"].replace(" ", "T") + "Z"
|
||||
|
||||
layers = "[" + ",".join(path) + ",1,100]"
|
||||
ctype, png = call(
|
||||
"takeScreenshot",
|
||||
date=meta["date"],
|
||||
date=shot_date,
|
||||
imageScale=0.6, # Bogensekunden/Pixel -> ~3400 px Vollscheibe
|
||||
layers=layers,
|
||||
x1=-1100,
|
||||
@@ -90,11 +95,10 @@ def main():
|
||||
watermark="false",
|
||||
)
|
||||
if not ctype.startswith("image"):
|
||||
sys.exit(f"unerwartete Antwort ({ctype}): {png[:200]!r}")
|
||||
sys.exit(f"unexpected response ({ctype}): {png[:200]!r}")
|
||||
|
||||
name = (
|
||||
f"{meta['date'].replace(':', '').replace('-', '')}_{nick.replace(' ', '')}.png"
|
||||
)
|
||||
stamp = meta["date"].replace(":", "").replace("-", "").replace(" ", "_")
|
||||
name = f"{stamp}_{nick.replace(' ', '')}.png"
|
||||
with open(name, "wb") as f:
|
||||
f.write(png)
|
||||
print(f"-> {name} ({len(png) / 1e6:.1f} MB)")
|
||||
|
||||
Reference in New Issue
Block a user