-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhemichltor.py
More file actions
42 lines (38 loc) · 1.3 KB
/
Copy pathhemichltor.py
File metadata and controls
42 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests
import time
def query(request):
request["action"] = "query"
request["format"] = "json"
lastContinue = {}
while True:
# Clone original request
req = request.copy()
# Modify with the values returned in the 'continue' section of the last result.
req.update(lastContinue)
# Call API
time.sleep(1)
result = requests.get(
"https://www.hamichlol.org.il/w/api.php", params=req
).json()
if "error" in result:
raise Error(result["error"])
if "warnings" in result:
print(result["warnings"])
if "query" in result:
yield result["query"]
if "continue" not in result:
break
lastContinue = result["continue"]
with open("torani.csv", "w", encoding="utf-8") as f:
for result in query(
{
"generator": "categorymembers",
"gcmtitle": "קטגוריה:המכלול: ערכים הנכללים בזים תורני",
"prop": "info",
}
):
for page in result["pages"]:
title = result["pages"][page]["title"]
size = result["pages"][page]["length"]
touched = result["pages"][page]["touched"]
f.write(title + "|" + str(size) + "|" + touched + "\n")