Created
March 13, 2021 15:24
-
-
Save rijkvp/7dcc78ffc8468153ab7d59fd12c8bb6b to your computer and use it in GitHub Desktop.
Export WRTS-lists
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
# This is a simple python script that lets you export WRTS (https://wrts.nl) lists to text/csv files | |
# Auth token: Get from your browser inspector when you're logging in | |
# List ID: The ID in the URL https://leren.wrts.nl/lists/[ID HERE] | |
# Tested in March 2021 | |
# By Rijk van Putten (@rijkvp) | |
import requests; | |
import json; | |
auth_token = input("Auth Token: ") | |
list_id = input("List ID: ") | |
output_name = input("Output to: ") | |
print("Downloading list (1/3)..") | |
html = requests.get("https://api.wrts.nl/api/v3/lists/{}".format(list_id), headers={"x-auth-token":auth_token}) | |
print("Converting list (2/3)..") | |
list_json = json.loads(html.text) | |
list_data = [] | |
for item in list_json["words_with_performance"]: | |
list_data.append(item["words"]) | |
text_str = "" # Text file separated by '=' | |
csv_str = "" # Comma Separated Values file e. g. for Excel spreadsheet | |
for item in list_data: | |
text_str += "{}={}\n".format(item[0], item[1]) | |
csv_str += "{},{}\n".format(item[0], item[1]) | |
print("{} {}".format(item[0], item[1])) | |
print("Saving output (3/3)..") | |
with open(output_name + ".txt", "w+") as f: | |
f.write(text_str) | |
print("Saved text to {}.txt".format(output_name)) | |
with open(output_name + ".csv", "w+") as f: | |
f.write(csv_str) | |
print("Saved CSV to {}.csv".format(output_name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment