wikiharvest bundle for the Azure containers (public inputs: the undated-marriage pool + sitelinks)
Browse files
wikiharvest/wiki_start_harvest.py
CHANGED
|
@@ -280,10 +280,14 @@ def harvest(langs=None):
|
|
| 280 |
continue
|
| 281 |
names = [SL.get(sp, {}).get("sl", {}).get(lang, ""), SL.get(sp, {}).get("lb", {}).get(lang, ""), SL.get(sp, {}).get("lb", {}).get("en", "")]
|
| 282 |
jobs.append((r, subj, t, [n for n in names if n]))
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
| 284 |
got = 0
|
| 285 |
-
|
| 286 |
-
|
|
|
|
| 287 |
resp = http(api + "?" + urllib.parse.urlencode({"action": "query", "prop": "revisions", "rvprop": "content", "rvslots": "main", "titles": titles, "format": "json", "redirects": 1, "maxlag": 5}))
|
| 288 |
if not resp:
|
| 289 |
time.sleep(15); continue
|
|
@@ -304,9 +308,9 @@ def harvest(langs=None):
|
|
| 304 |
if ey and sy > min(ey):
|
| 305 |
continue
|
| 306 |
w.writerow([r["a"], r["b"], st, prec, lang, subj, snip.replace("\n", " "), endy if endy is not None else ""]); got += 1
|
| 307 |
-
if i %
|
| 308 |
f.flush(); log(f" {lang}: {i:,}/{len(jobs):,} read · {got:,} dates found")
|
| 309 |
-
time.sleep(0.
|
| 310 |
log(f" {lang}: DONE — {got:,} wedding dates found")
|
| 311 |
return got
|
| 312 |
langs = langs or LANGS
|
|
|
|
| 280 |
continue
|
| 281 |
names = [SL.get(sp, {}).get("sl", {}).get(lang, ""), SL.get(sp, {}).get("lb", {}).get(lang, ""), SL.get(sp, {}).get("lb", {}).get("en", "")]
|
| 282 |
jobs.append((r, subj, t, [n for n in names if n]))
|
| 283 |
+
shard = os.environ.get("AQ_JOB_SHARD", "")
|
| 284 |
+
if shard:
|
| 285 |
+
k, n = (int(x) for x in shard.split("/")); jobs = jobs[k::n]
|
| 286 |
+
log(f" {lang}: {len(jobs):,} article reads queued" + (f" (shard {shard})" if shard else ""))
|
| 287 |
got = 0
|
| 288 |
+
BATCH = int(os.environ.get("AQ_TITLES_PER_REQ", "50"))
|
| 289 |
+
for i in range(0, len(jobs), BATCH):
|
| 290 |
+
chunk = jobs[i:i + BATCH]; titles = "|".join(dict.fromkeys(j[2] for j in chunk))
|
| 291 |
resp = http(api + "?" + urllib.parse.urlencode({"action": "query", "prop": "revisions", "rvprop": "content", "rvslots": "main", "titles": titles, "format": "json", "redirects": 1, "maxlag": 5}))
|
| 292 |
if not resp:
|
| 293 |
time.sleep(15); continue
|
|
|
|
| 308 |
if ey and sy > min(ey):
|
| 309 |
continue
|
| 310 |
w.writerow([r["a"], r["b"], st, prec, lang, subj, snip.replace("\n", " "), endy if endy is not None else ""]); got += 1
|
| 311 |
+
if i % (BATCH * 20) == 0 and i:
|
| 312 |
f.flush(); log(f" {lang}: {i:,}/{len(jobs):,} read · {got:,} dates found")
|
| 313 |
+
time.sleep(float(os.environ.get("AQ_READ_SLEEP", "0.25")))
|
| 314 |
log(f" {lang}: DONE — {got:,} wedding dates found")
|
| 315 |
return got
|
| 316 |
langs = langs or LANGS
|