feat: migrate to direct API, refactor lib into claim/claims/bot layers#83
feat: migrate to direct API, refactor lib into claim/claims/bot layers#83
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the bot framework to remove the dependency on pywikibot, replacing it with a custom BaseBot and Claim system that interacts directly with the Wikimedia Commons API via requests. Key changes include the introduction of ClaimsMixin for structured data management and the migration of individual bots (Flickr, iNaturalist, PAS, YouTube) to this new architecture. Review feedback highlights a potential regression where the bot no longer checks if it has already contributed to a page before processing, and suggests simplifying ISO date parsing by leveraging native Python 3.11+ features.
I am having trouble creating individual review comments. Click here to see my feedback.
src/wikibots/inaturalist.py (77-83)
This skip_page implementation, which prevented the bot from processing pages it has already contributed to, has been removed. The new BaseBot implementation does not seem to replicate the self.commons.username() in page.contributors() check. This could lead to the bot re-processing pages it has already edited, which might be inefficient or lead to unintended behavior if the Redis cache is cleared. Was this intentional? If not, you might want to add a mechanism to fetch contributors and perform this check in the new BaseBot or in the skip_page hook.
src/wikibots/flickr.py (88-90)
Since the project uses Python 3.13, datetime.fromisoformat() can directly handle the 'Z' suffix for UTC. The .replace("Z", "+00:00") is redundant and can be removed for cleaner code.
date_posted_dt = datetime.fromisoformat(date_posted)
Replaces pywikibot with direct MediaWiki/Wikibase API calls and restructures
lib/into three focused modules:lib/claim.py—Claimtyped builder (factory methods + mutation methods),WbTime,WikiProperties. All raw snak/dict logic is private here; bots never touch dicts.lib/claims.py—ClaimsMixinwith allcreate_*methods and hook stubs.lib/bot.py—BaseBot(ClaimsMixin)with OAuth2, Redis, HTTP sessions, run loop, and Commons/Wikidata API calls.Other changes:
flickr-photos-apiv2 → v3 (flickr_api); catchesPermissionDeniedinstead of removedPhotoIsPrivatealways_null_edit, dry-run mode,TOOL_REDIS_URIenv var supportdatetimeobjects to claim methods;WbTimeconstruction is internal