Created
October 11, 2024 03:00
-
-
Save audiodude/028ce1e540f65f22e8378920eea65784 to your computer and use it in GitHub Desktop.
Psuedo code for updating wikitionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# csv is built in | |
import csv | |
# requests must be installed with `pip`. See also: virtual environment. | |
import requests | |
# #Use this instead of reader[:10] to get a random 10 instead of the first ten. | |
# import random | |
# random.sample(reader, 10) | |
# Double quoted strings will allow for multiple lines, but all of the whitespace will be preserved, | |
# including the newline between the first """ and the next line. | |
template = """ | |
{word} ({pos}): {def_} | |
""" | |
with open('words.csv') as f: | |
reader = csv.reader(f) | |
for row in reader[:10]: | |
entry = template.format( | |
word=row[0], | |
pos=row[1], | |
def_=row[2], | |
) | |
# 1. Get any required tokens, including OAuth for authentication if required | |
# 2. Make a GET request to created the article ('articledata' is probably not the right param!) | |
# (row[0], the word, is used as the title) | |
# TODO: Lookup how to add the KEA category | |
requests.get('https://en.wiktionary.org/w/api.php', | |
data={ | |
'action': 'edit', | |
'title': f'User:myusername/testdefs/{row[0]}', | |
'articledata': entry | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment