-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (94 loc) · 2.71 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from flask import Flask, render_template, request, Response
from flashcard_maker import generate_flashcards, generate_flashcards_with_note
import genanki
import openai
openai.api_key = "" # key is deleted for security reasons
arr =[]
#Set up website with index.html
app = Flask(__name__)
@app.route('/')
def render_home():
return render_template('index.html')
@app.route('/note')
def render_note():
print("note")
return render_template('index2.html')
@app.route('/ajax_get_cards', methods=['POST'])
def ajax_send_cards():
data = request.get_json()
grade = data['grade']
topic = data['topic']
NumofCards = data['NumofCards']
details = data['details']
return generate_flashcards([grade, topic, NumofCards, details])
@app.route('/note/ajax_create_cards', methods=['POST'])
def ajax_get_note():
data = request.get_json()
note = data['note']
NumofCards = data['NumofCards']
ex = data['ex']
arr=generate_flashcards_with_note([note, ex, NumofCards])
return arr
#DOWNLOAD
@app.route('/download-deck')
def download_deck():
questions=[]
answers=[]
for i in range (0, arr.len()):
questions.append(arr[i])
answers.append(arr[i])
# create an Anki deck
model = genanki.Model(
1607392319,
'Simple Model',
fields=[{'name': 'Question'}, {'name': 'Answer'}],
templates=[{
'name': 'Card 1',
'qfmt': '{{Question}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
}]
)
if 'app' == '__main__':
app.run()
app.run(host='0.0.0.0', port=8080, debug=True)
#DOWNLOAD
@app.route('/download-deck')
def download_deck():
questions=[]
answers=[]
for i in range (0, arr.len()):
questions.append(arr[i])
answers.append(arr[i])
# create an Anki deck
model = genanki.Model(
1607392319,
'Simple Model',
fields=[{'name': 'Question'}, {'name': 'Answer'}],
templates=[{
'name': 'Card 1',
'qfmt': '{{Question}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
}]
)
deck = genanki.Deck(
2059400110,
'Example Deck'
)
for i in range(len(questions)):
note = genanki.Note(
model=model,
fields=[questions[i], answers[i]]
)
deck.add_note(note)
# return the deck as a file
deck_bytes = deck.write_to_bytes()
return Response(
deck_bytes,
mimetype='application/octet-stream',
headers={
'Content-Disposition': 'attachment; filename=example_deck.apkg'
}
)
if 'app' == '__main__':
app.run()
app.run(host='0.0.0.0', port=8080, debug=True)