56 lines
1.9 KiB
Python
Executable File
56 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import requests
|
|
import json
|
|
def get_more_words():
|
|
# we're doing these 500 at a time so we can get some semblance of
|
|
# randomness
|
|
max_words: str = "500"
|
|
new_continue_point: str
|
|
|
|
with open("./continue_file", "r") as continue_file:
|
|
continue_point = continue_file.read()
|
|
|
|
if continue_point.strip() != "":
|
|
url: str = ("https://en.wiktionary.org/w/api.php?action=query"
|
|
+ "&format=json"
|
|
+ "&generator=categorymembers"
|
|
+ "&gcmnamespace=0"
|
|
+ "&gcmtitle=Category:English_uncountable_nouns"
|
|
+ "&gcmsort=timestamp"
|
|
+ "&gcmlimit=" + max_words
|
|
+ "&gcmcontinue=" + continue_point)
|
|
else:
|
|
url: str = ("https://en.wiktionary.org/w/api.php?action=query"
|
|
+ "&format=json"
|
|
+ "&generator=categorymembers"
|
|
+ "&gcmnamespace=0"
|
|
+ "&gcmtitle=Category:English_uncountable_nouns"
|
|
+ "&gcmsort=timestamp"
|
|
+ "&gcmlimit=" + max_words)
|
|
|
|
response: requests.Response = requests.get(url)
|
|
response_json: dict
|
|
words: list
|
|
|
|
if response.ok:
|
|
response_json = response.json()
|
|
else:
|
|
print("request failed with status code {}: {}"
|
|
.format(response.status_code, response.reason))
|
|
return False
|
|
|
|
new_continue_point = response_json["continue"]["gcmcontinue"]
|
|
words = response_json["query"]["pages"].values()
|
|
words = list(map(lambda x: x["title"], words))
|
|
|
|
with open("./good_words", "a") as good_words_file:
|
|
for word in words:
|
|
good_words_file.write(word + "\n")
|
|
print("wrote new words to file")
|
|
|
|
with open("./continue_file", "w") as continue_file:
|
|
continue_file.write(new_continue_point)
|
|
print("set to continue from " + new_continue_point)
|
|
|
|
get_more_words()
|