diff --git a/scripts/scicore-watch.sh b/scripts/scicore-watch.sh index 867c61e..c32c2e3 100755 --- a/scripts/scicore-watch.sh +++ b/scripts/scicore-watch.sh @@ -51,13 +51,27 @@ $URL" fi echo 0 > "$FAILS" -CURRENT=$(printf '%s' "$HTML" | python3 -c ' -import sys, re, html +CURRENT=$(printf '%s' "$HTML" | SCICORE_BASE="$URL" python3 -c ' +import sys, re, html, os +from urllib.parse import urljoin +BASE = os.environ.get("SCICORE_BASE", "") h = sys.stdin.read() m = re.search(r"

Join the team!

(.*?)", "", body, flags=re.S | re.I) body = re.sub(r"]*>", "\n- ", body, flags=re.I) + +# Keep the posting URL: Role -> "Role -> X", so the alert can be +# tapped straight through to the application page instead of the listing index. +QUOTES = chr(34) + chr(39) +A_TAG = "]*href=([" + QUOTES + "])(.*?)\\1[^>]*>(.*?)" +def keep_link(m): + href = html.unescape(m.group(2)).strip() + text = re.sub(r"<[^>]+>", "", m.group(3)).strip() + if not href or href.startswith(("#", "mailto:", "javascript:")): + return text + return "{} -> {}".format(text, urljoin(BASE, href)) +body = re.sub(A_TAG, keep_link, body, flags=re.S | re.I) body = re.sub(r"", "\n", body, flags=re.I) body = re.sub(r"<[^>]+>", " ", body) body = html.unescape(body)