-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword_forms_crawler.py
49 lines (40 loc) · 1.53 KB
/
word_forms_crawler.py
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
43
44
45
46
47
48
49
import pywikibot
from api.entryprocessor import WiktionaryProcessorFactory
from word_forms import create_non_lemma_entry
def crawl_categories_list():
done = set()
task_list = set()
with open("user_data/crawled", "r") as crawled:
for line in crawled:
done.add(line.strip("\n"))
with open("user_data/crawled", "w") as crawled:
with open("user_data/categories", "r") as f:
for line in f:
task_list.add(line.strip("\n"))
remaining = task_list.difference(done)
for line in remaining:
crawl_subcategories(line)
crawled.write(line)
def crawl_subcategories(category_name):
working_language = "en"
# Initialise processor class
en_page_processor_class = WiktionaryProcessorFactory.create(working_language)
en_page_processor = en_page_processor_class()
print(category_name)
category = pywikibot.Category(
pywikibot.Site(working_language, "wiktionary"), category_name
)
if not category.isEmptyCategory():
pywikibot.output("▒▒ \03{green}%-25s\03{default} ▒▒" % category.title())
for article in category.articles():
pywikibot.output(article.title())
en_page_processor.process(article)
entries = en_page_processor.get_all_entries(definitions_as_is=True)
print(article, entries)
for entry in entries:
create_non_lemma_entry(entry)
if __name__ == "__main__":
try:
crawl_categories_list()
finally:
pass