Skip to content

feat: migrate to direct API, refactor lib into claim/claims/bot layers#83

Merged
DaxServer merged 1 commit intomainfrom
feat/migrate-to-direct-api
Apr 10, 2026
Merged

feat: migrate to direct API, refactor lib into claim/claims/bot layers#83
DaxServer merged 1 commit intomainfrom
feat/migrate-to-direct-api

Conversation

@DaxServer
Copy link
Copy Markdown
Owner

Replaces pywikibot with direct MediaWiki/Wikibase API calls and restructures lib/ into three focused modules:

  • lib/claim.pyClaim typed builder (factory methods + mutation methods), WbTime, WikiProperties. All raw snak/dict logic is private here; bots never touch dicts.
  • lib/claims.pyClaimsMixin with all create_* methods and hook stubs.
  • lib/bot.pyBaseBot(ClaimsMixin) with OAuth2, Redis, HTTP sessions, run loop, and Commons/Wikidata API calls.

Other changes:

  • Adds iNaturalist and PAS bots (previously missing entry points)
  • Bumps flickr-photos-api v2 → v3 (flickr_api); catches PermissionDenied instead of removed PhotoIsPrivate
  • Adds always_null_edit, dry-run mode, TOOL_REDIS_URI env var support
  • Bots pass datetime objects to claim methods; WbTime construction is internal

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

high

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)

medium

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)

@DaxServer DaxServer merged commit cb2c48a into main Apr 10, 2026
4 checks passed
@DaxServer DaxServer deleted the feat/migrate-to-direct-api branch April 10, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant