Skip to content

Commit

Permalink
Better changelog parsing
Browse files Browse the repository at this point in the history
When merging live firmwares, override the changelogs instead of
appending to them to avoid cases like
b61e378.
Use lxml in parse_changes() instead of a regex to avoid edge cases such
as 236bdae.
  • Loading branch information
AT0myks committed Nov 4, 2023
1 parent c00b359 commit 18217af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 1 addition & 3 deletions firmwares_live.json
Original file line number Diff line number Diff line change
Expand Up @@ -2718,9 +2718,7 @@
"firmware_id": 434,
"model": "E1 Outdoor Pro",
"hw_ver": "IPC_560SD88MP",
"changelog": [
""
],
"changelog": [],
"display_time": "2023-08-29 00:00:00+08:00",
"sha256_pak": "17082f0ee33a7e035497e1078ea3ff863123cd867580adbc46eeade4595dcb66",
"source": "live"
Expand Down
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ def sanitize(string: str) -> str:

def parse_changes(text: str) -> list[str]:
text = sanitize(text)
text = text.removeprefix("<p>").removesuffix("</p>")
text = text.removeprefix("<P>").removesuffix("</P>")
return re.split("\s*</?[pP]>\s*<[pP]>\s*|\s*<br />\s*", text)
frag = fragment_fromstring(text, True)
return [text.strip() for text in frag.itertext() if text.strip()]


def parse_timestamps(display_time: int, updated_at: int) -> tuple[datetime, datetime]:
Expand Down Expand Up @@ -406,6 +405,8 @@ def merge_dicts(old: MutableMapping[Any, Any], new: Mapping[Any, Any]) -> None:
if key in ("productImg", "productUrl"): # For device merging.
if val: # Avoid replacing manually set value by an empty live value.
old[key] = val
elif key == "changelog": # For live firmware merging.
old[key] = val
elif isinstance(val, dict):
if not isinstance(old.get(key), dict):
old[key] = {}
Expand Down

0 comments on commit 18217af

Please sign in to comment.