Created
November 14, 2022 21:58
-
-
Save apeyroux/060971a9213e3a0f8795bbb534b28efe to your computer and use it in GitHub Desktop.
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
import json | |
import requests | |
from bs4 import BeautifulSoup | |
import sys | |
with open('voc.json') as f: | |
voc = json.load(f) | |
for m in voc['fr']['3']['favoris']: | |
mot = m['favori']['graphie'].capitalize() | |
definition_html = m['apercu'] | |
definition = BeautifulSoup(definition_html, 'html.parser').text | |
resp = requests.post( | |
url="https://readwise.io/api/v2/highlights/", | |
headers={"Authorization": "Token xxxxx"}, | |
json={ | |
"highlights": [{ | |
"text": definition, | |
"title": mot, | |
"note": ".vocabulaire", | |
"author": "Antidote", | |
"source_type": "antidote2readwise", | |
"category": "articles" | |
}] | |
} | |
) | |
if resp.status_code != 200: | |
print(resp.status_code) | |
print(resp.text) | |
else: | |
print("Added {} ...".format(mot)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment