-
Notifications
You must be signed in to change notification settings - Fork 0
/
anki_api.py
38 lines (33 loc) · 1009 Bytes
/
anki_api.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
import requests
import json
def add_card(deck_name, note_type, front_text, back_text):
# AnkiConnect URL
url = "http://localhost:8765"
# Define the JSON payload to send to AnkiConnect
payload = {
"action": "addNote",
"version": 6,
"params": {
"note": {
"deckName": deck_name,
"modelName": note_type,
"fields": {
"Front": front_text,
"Back": back_text
},
"options": {
"allowDuplicate": False
},
"tags": []
}
}
}
# Send the request to AnkiConnect
response = requests.post(url, json=payload)
# Check the response
if response.status_code == 200:
print("Card added successfully.")
else:
print(f"Failed to add card: {response.text}")
# Example usage
add_card("Default", "Basic", "What is the capital of France?", "Paris")