summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar klea2025-12-18 00:09:51 +0000
committerGravatar klea2025-12-18 00:09:51 +0000
commitf45b85742daee787e79ee798d1ef4163f65c2dd2 (patch)
tree401396d31179b4b1c3131fda159ed770572d1828
parentwikibot/inthemedia: first 20, made it as variable (diff)
signature
wiki-recentchanges: update for #at-changes
-rwxr-xr-xbin/wiki-recentchanges.py36
1 files changed, 13 insertions, 23 deletions
diff --git a/bin/wiki-recentchanges.py b/bin/wiki-recentchanges.py
index 46371a2..f94f1b6 100755
--- a/bin/wiki-recentchanges.py
+++ b/bin/wiki-recentchanges.py
@@ -7,6 +7,9 @@ import typing
import urllib.parse
+ATW="https://wiki.archiveteam.org/"
+ATAPI = ATW + "api.php"
+
def get_new(newestRc: typing.Optional[tuple[str, int]]) -> tuple[list[dict], tuple[str, int]]:
'''
Fetches edits made after newestRc = (newestTimestamp, newestRcId), which shall both refer to the last change already known/processed.
@@ -21,7 +24,7 @@ def get_new(newestRc: typing.Optional[tuple[str, int]]) -> tuple[list[dict], tup
else:
newestTimestamp, newestRcId = newestRc
rcend = f'&rcend={newestTimestamp}' if newestTimestamp else ''
- r = requests.get(f'https://wiki.archiveteam.org/api.php?action=query&list=recentchanges&rcdir=older&format=json&rcprop=user|comment|timestamp|sizes|title|flags|ids|loginfo&continue=&rclimit=500{rcend}',
+ r = requests.get(f'{ATAPI}?action=query&list=recentchanges&rcdir=older&format=json&rcprop=user|comment|timestamp|sizes|title|flags|ids|loginfo&continue=&rclimit=500{rcend}',
timeout = 5,
)
r.raise_for_status()
@@ -54,37 +57,27 @@ def truncate(s: str, limit: int) -> str:
def format_change(change: dict) -> typing.Optional[str]:
'''Formats a change for posting to IRC. Returns None if it's an event that isn't handled and not to be reported to IRC.'''
- lenChange = False
title = change['title']
+ urlSafeTitle = urllib.parse.quote(change['title'])
url = None
if change['type'] == 'new':
verb = 'created'
- url = f'https://wiki.archiveteam.org/?title={urllib.parse.quote(change["title"])}'
- lenChange = True
+ url = f'{ATW}?title={urlSafeTitle}&oldid={change["revid"]}'
elif change['type'] == 'edit':
verb = 'edited'
- url = f'https://wiki.archiveteam.org/?diff={change["revid"]}&oldid={change["old_revid"]}'
- lenChange = True
+ url = f'{ATW}?title={urlSafeTitle}&diff={change["revid"]}&oldid={change["old_revid"]}'
elif change['type'] == 'log' and change['logtype'] == 'delete':
verb = 'deleted'
url = ''
- elif change['type'] == 'log' and change['logtype'] == 'upload':
- verb = 'uploaded'
- url = f'https://wiki.archiveteam.org/?title={urllib.parse.quote(change["title"])}'
elif change['type'] == 'log' and change['logtype'] == 'move':
verb = 'moved'
- title = f'{change["title"]} to {change["logparams"]["target_title"]}'
- url = f'https://wiki.archiveteam.org/?title={urllib.parse.quote(change["logparams"]["target_title"])}'
- elif change['type'] == 'log' and change['logtype'] == 'rights':
- verb = 'changed the user rights of'
+ title = f'{change["logparams"]["target_title"]} (from {change["title"]})'
+ url = f'{ATW}?title={urllib.parse.quote(change["logparams"]["target_title"])}'
else:
return
- comment = f'{truncate(change["comment"], 50)}' if change["comment"] else ''
- lenChange = f'{change["newlen"] - change["oldlen"]:+d}' if lenChange else ''
- joiner = ', ' if comment and lenChange else ''
- lenChangeAndComment = f' ({lenChange}{joiner}{comment})' if lenChange or comment else ''
- url = f': {url}' if url else ''
- return f'{change["user"]} {verb} {title}{lenChangeAndComment}{url}'
+ comment = change["comment"] if change["comment"] else ''
+ url = f'{url}' if url else ''
+ return f'AT Wiki | {title} was {verb} by {change["user"]} at {change["timestamp"]} | {comment} | {url}'
def main():
@@ -99,11 +92,8 @@ def main():
time.sleep(60)
continue
for change in changes:
- if change['ns'] in (2, 3) and change['type'] != 'log':
- logging.info(f'Skipping user namespace change: {change!r}')
- continue
formatted = format_change(change)
- if formatted and not any(ord(c) < 32 for c in formatted):
+ if formatted:
print(formatted, flush = True)
else:
logging.warning(f'Suppressed change because it was un- or ill-formatted: {change!r}')