forked from zhaofeng-shu33/DeutschLernen_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bunch_add.py
36 lines (30 loc) · 1.02 KB
/
bunch_add.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
# add a bunch of words from txt format
from django.test import Client
import django
from Word_edit import html_form_to_xml
django.setup()
client = Client()
def add_word_using_api(index, word):
parts = word.split(' ')
data = {'Stichwort' : parts[0],
'category' : 'Substantiv',
'isCreated' : 'True',
'wordAddr' : '/Wort/ja/%d.xml' % index,
'explanation_1': parts[0]
}
if len(parts) > 1:
data['Aussprache'] = parts[1].rstrip()
if len(parts) > 2:
data['explanation_1'] = parts[2]
response = client.post('/Word_edit/create_new_word', data)
assert(response.status_code == 200)
if __name__ == '__main__':
# treat all words as Substantiv
noun_len = html_form_to_xml.next_word_address(word_type='Substantiv')
noun_len = int(noun_len)
with open('build/word.txt') as f:
word = f.readline()
while word != '':
add_word_using_api(noun_len, word)
noun_len += 1
word = f.readline()