summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorGravatar klea2025-12-18 00:10:33 +0000
committerGravatar klea2025-12-18 00:10:42 +0000
commit237dd4e55e2d139edd542e0c5eaba664b33e5fa8 (patch)
tree95c2edd9ba465e6db4b9002d2d4984aa2ef90833 /bin
parentwiki-recentchanges: update for #at-changes (diff)
signature
wiki-recentchanges: move to root
Diffstat (limited to 'bin')
-rwxr-xr-xbin/wiki-recentchanges.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/bin/wiki-recentchanges.py b/bin/wiki-recentchanges.py
index f94f1b6..46371a2 100755
--- a/bin/wiki-recentchanges.py
+++ b/bin/wiki-recentchanges.py
@@ -7,9 +7,6 @@ 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.
@@ -24,7 +21,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'{ATAPI}?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'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}',
timeout = 5,
)
r.raise_for_status()
@@ -57,27 +54,37 @@ 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'{ATW}?title={urlSafeTitle}&oldid={change["revid"]}'
+ url = f'https://wiki.archiveteam.org/?title={urllib.parse.quote(change["title"])}'
+ lenChange = True
elif change['type'] == 'edit':
verb = 'edited'
- url = f'{ATW}?title={urlSafeTitle}&diff={change["revid"]}&oldid={change["old_revid"]}'
+ url = f'https://wiki.archiveteam.org/?diff={change["revid"]}&oldid={change["old_revid"]}'
+ lenChange = True
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["logparams"]["target_title"]} (from {change["title"]})'
- url = f'{ATW}?title={urllib.parse.quote(change["logparams"]["target_title"])}'
+ 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'
else:
return
- 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}'
+ 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}'
def main():
@@ -92,8 +99,11 @@ 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:
+ if formatted and not any(ord(c) < 32 for c in formatted):
print(formatted, flush = True)
else:
logging.warning(f'Suppressed change because it was un- or ill-formatted: {change!r}')