Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying language variant #209

Open
XapaJIaMnu-at-meta opened this issue Oct 24, 2024 · 2 comments
Open

Allow specifying language variant #209

XapaJIaMnu-at-meta opened this issue Oct 24, 2024 · 2 comments

Comments

@XapaJIaMnu-at-meta
Copy link

Some wikipedia pages (such as Serbian and Chinese) have multiple language variants that are equivalent.

Fetching the content is then dependent on the variant variable in the API: https://zh.wikipedia.org/wiki/Special:API%E6%B2%99%E7%9B%92?uselang=en#action=parse&format=json&variant=zh-tw&page=Main%20Page&formatversion=2

I'm currently working around this by monkey-patching the wikipediaapi.Wikipedia._query method like this:

def patched_query(self, page: "WikipediaPage", params: dict[str, Any]):
        """Queries Wikimedia API to fetch content."""
        print(self._request_kwargs)
        if 'variant' in self._request_kwargs:
            params['variant'] = self._request_kwargs['variant']
            del(self._request_kwargs['variant'])
        base_url = "https://" + page.language + ".wikipedia.org/w/api.php"
        #log.info(
        #    "Request URL: %s",
        #    base_url + "?" + "&".join([k + "=" + str(v) for k, v in params.items()])
        #)
        params["format"] = "json"
        params["redirects"] = 1
        print(params)
        r = self._session.get(base_url, params=params, **self._request_kwargs)
        return r.json()

Ideally there would be a way to specify extra params that go to the wikipedia call, not just to the request library.

Copy link

github-actions bot commented Dec 9, 2024

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 9, 2024
Copy link

This issue was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2024
@martin-majlis martin-majlis reopened this Jan 4, 2025
@github-actions github-actions bot removed the Stale label Jan 5, 2025
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

No branches or pull requests

2 participants