Move format_launch_changes to agenda.thespacedevs
This commit is contained in:
parent
bc4d956042
commit
fd7488bd04
|
@ -183,3 +183,68 @@ def get_launches(
|
|||
filename = os.path.join(rocket_dir, f)
|
||||
data = json.load(open(filename))
|
||||
return [summarize_launch(launch) for launch in data["results"]]
|
||||
|
||||
|
||||
def format_launch_changes(differences: StrDict) -> str:
|
||||
"""Convert deepdiff output to human-readable format."""
|
||||
changes = []
|
||||
# Handle value changes
|
||||
if "values_changed" in differences:
|
||||
for path, change in differences["values_changed"].items():
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
old_val = change["old_value"]
|
||||
new_val = change["new_value"]
|
||||
# Format specific fields nicely
|
||||
if field == "net":
|
||||
try:
|
||||
old_dt = datetime.fromisoformat(old_val.replace("Z", "+00:00"))
|
||||
new_dt = datetime.fromisoformat(new_val.replace("Z", "+00:00"))
|
||||
changes.append(
|
||||
"Launch time changed from "
|
||||
+ old_dt.strftime("%d %b %Y at %H:%M UTC")
|
||||
+ " to "
|
||||
+ new_dt.strftime("%d %b %Y at %H:%M UTC")
|
||||
)
|
||||
except:
|
||||
changes.append(f"Launch time changed from {old_val} to {new_val}")
|
||||
elif field == "name":
|
||||
changes.append(f"Mission name changed from '{old_val}' to '{new_val}'")
|
||||
elif field == "probability":
|
||||
if old_val is None:
|
||||
changes.append(f"Launch probability set to {new_val}%")
|
||||
elif new_val is None:
|
||||
changes.append("Launch probability removed")
|
||||
else:
|
||||
changes.append(
|
||||
f"Launch probability changed from {old_val}% to {new_val}%"
|
||||
)
|
||||
elif "status" in field:
|
||||
changes.append(f"Status changed from '{old_val}' to '{new_val}'")
|
||||
else:
|
||||
changes.append(
|
||||
f"{field.replace('_', ' ').title()} changed "
|
||||
+ f"from '{old_val}' to '{new_val}'"
|
||||
)
|
||||
# Handle additions
|
||||
if "dictionary_item_added" in differences:
|
||||
for path in differences["dictionary_item_added"]:
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
changes.append(f"New field added: {field.replace('_', ' ').title()}")
|
||||
# Handle removals
|
||||
if "dictionary_item_removed" in differences:
|
||||
for path in differences["dictionary_item_removed"]:
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
changes.append(f"Field removed: {field.replace('_', ' ').title()}")
|
||||
# Handle type changes
|
||||
if "type_changes" in differences:
|
||||
for path, change in differences["type_changes"].items():
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
changes.append(
|
||||
f"{field.replace('_', ' ').title()} type changed "
|
||||
+ f"from {change['old_type'].__name__} to {change['new_type'].__name__}"
|
||||
)
|
||||
return (
|
||||
"\n".join(f"• {change}" for change in changes)
|
||||
if changes
|
||||
else "No specific changes detected"
|
||||
)
|
||||
|
|
67
update.py
67
update.py
|
@ -109,71 +109,6 @@ Agenda: https://edwardbetts.com/agenda/
|
|||
agenda.mail.send_mail(config, subject, body)
|
||||
|
||||
|
||||
def format_launch_changes(differences: StrDict) -> str:
|
||||
"""Convert deepdiff output to human-readable format."""
|
||||
changes = []
|
||||
# Handle value changes
|
||||
if "values_changed" in differences:
|
||||
for path, change in differences["values_changed"].items():
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
old_val = change["old_value"]
|
||||
new_val = change["new_value"]
|
||||
# Format specific fields nicely
|
||||
if field == "net":
|
||||
try:
|
||||
old_dt = datetime.fromisoformat(old_val.replace("Z", "+00:00"))
|
||||
new_dt = datetime.fromisoformat(new_val.replace("Z", "+00:00"))
|
||||
changes.append(
|
||||
"Launch time changed from "
|
||||
+ old_dt.strftime("%d %b %Y at %H:%M UTC")
|
||||
+ " to "
|
||||
+ new_dt.strftime("%d %b %Y at %H:%M UTC")
|
||||
)
|
||||
except:
|
||||
changes.append(f"Launch time changed from {old_val} to {new_val}")
|
||||
elif field == "name":
|
||||
changes.append(f"Mission name changed from '{old_val}' to '{new_val}'")
|
||||
elif field == "probability":
|
||||
if old_val is None:
|
||||
changes.append(f"Launch probability set to {new_val}%")
|
||||
elif new_val is None:
|
||||
changes.append("Launch probability removed")
|
||||
else:
|
||||
changes.append(
|
||||
f"Launch probability changed from {old_val}% to {new_val}%"
|
||||
)
|
||||
elif "status" in field:
|
||||
changes.append(f"Status changed from '{old_val}' to '{new_val}'")
|
||||
else:
|
||||
changes.append(
|
||||
f"{field.replace('_', ' ').title()} changed "
|
||||
+ f"from '{old_val}' to '{new_val}'"
|
||||
)
|
||||
# Handle additions
|
||||
if "dictionary_item_added" in differences:
|
||||
for path in differences["dictionary_item_added"]:
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
changes.append(f"New field added: {field.replace('_', ' ').title()}")
|
||||
# Handle removals
|
||||
if "dictionary_item_removed" in differences:
|
||||
for path in differences["dictionary_item_removed"]:
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
changes.append(f"Field removed: {field.replace('_', ' ').title()}")
|
||||
# Handle type changes
|
||||
if "type_changes" in differences:
|
||||
for path, change in differences["type_changes"].items():
|
||||
field = path.replace("root['", "").replace("']", "").replace("root.", "")
|
||||
changes.append(
|
||||
f"{field.replace('_', ' ').title()} type changed "
|
||||
+ f"from {change['old_type'].__name__} to {change['new_type'].__name__}"
|
||||
)
|
||||
return (
|
||||
"\n".join(f"• {change}" for change in changes)
|
||||
if changes
|
||||
else "No specific changes detected"
|
||||
)
|
||||
|
||||
|
||||
def report_space_launch_change(
|
||||
config: flask.config.Config, prev_launch: StrDict | None, cur_launch: StrDict | None
|
||||
) -> None:
|
||||
|
@ -277,7 +212,7 @@ View all launches: https://edwardbetts.com/agenda/launches
|
|||
subject = f"Space Launch Update: {name}"
|
||||
|
||||
differences = deepdiff.DeepDiff(prev_launch, cur_launch)
|
||||
changes_text = format_launch_changes(differences)
|
||||
changes_text = agenda.thespacedevs.format_launch_changes(differences)
|
||||
# Format launch date nicely
|
||||
formatted_date = "Unknown"
|
||||
if launch_date and launch_date != "Unknown":
|
||||
|
|
Loading…
Reference in a new issue