feat: include posting links in sciCORE watch alerts

Keep each vacancy's href when flattening the listing HTML, resolved to an
absolute URL, so the Telegram alert links straight to the application page
instead of the listing index.

The extractor runs as python3 -c inside shell single quotes, so the anchor
pattern's quote class is built with chr(39) rather than written inline.
This commit is contained in:
2026-08-27 09:28:58 +02:00
parent 2402b5d5da
commit acfdcf97a0
+16 -2
View File
@@ -51,13 +51,27 @@ $URL"
fi fi
echo 0 > "$FAILS" echo 0 > "$FAILS"
CURRENT=$(printf '%s' "$HTML" | python3 -c ' CURRENT=$(printf '%s' "$HTML" | SCICORE_BASE="$URL" python3 -c '
import sys, re, html import sys, re, html, os
from urllib.parse import urljoin
BASE = os.environ.get("SCICORE_BASE", "")
h = sys.stdin.read() h = sys.stdin.read()
m = re.search(r"<h1>Join the team!</h1>(.*?)<footer", h, re.S | re.I) m = re.search(r"<h1>Join the team!</h1>(.*?)<footer", h, re.S | re.I)
body = m.group(1) if m else h body = m.group(1) if m else h
body = re.sub(r"<(script|style).*?</\1>", "", body, flags=re.S | re.I) body = re.sub(r"<(script|style).*?</\1>", "", body, flags=re.S | re.I)
body = re.sub(r"<li[^>]*>", "\n- ", body, flags=re.I) body = re.sub(r"<li[^>]*>", "\n- ", body, flags=re.I)
# Keep the posting URL: <a href="X">Role</a> -> "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 = "<a\\s[^>]*href=([" + QUOTES + "])(.*?)\\1[^>]*>(.*?)</a>"
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"</(p|div|h[1-6]|ul|li|tr)>", "\n", body, flags=re.I) body = re.sub(r"</(p|div|h[1-6]|ul|li|tr)>", "\n", body, flags=re.I)
body = re.sub(r"<[^>]+>", " ", body) body = re.sub(r"<[^>]+>", " ", body)
body = html.unescape(body) body = html.unescape(body)