#!/usr/bin/env python3
"""Collect a pool of TeX formulas from Wikipedia wikitext (CC BY-SA 4.0).
Usage: wikipedia_tex.py --work DIR --out FILE [--seed N] [--target N]
[--en-pages N] [--other-pages N]
Finds math-heavy articles with the MediaWiki search API (`list=search`,
field keywords per language: mathematics, physics, chemistry, statistics,
engineering, economics), downloads their current wikitext with
`prop=revisions&rvprop=content|ids` (20 pages per request, one request per
second) and extracts the content of `", re.S)
BAD = re.compile(r"\{\{| record
pages_used = []
for lang, terms in TERMS.items():
info = cached(work, api(lang, action="query", meta="siteinfo", siprop="rightsinfo"))
rights = info["query"]["rightsinfo"]
if "by-sa/4.0" not in rights["url"]:
cc.log("skip", lang, "rights", rights)
continue
titles = []
npages = a.en_pages if lang == "en" else a.other_pages
for term in terms:
got = 0
off = 0
while got < npages:
lim = min(50, npages - got)
d = cached(work, api(lang, action="query", list="search", srsearch=term + ' insource:"