forked from 251321639/wechat_brain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
68 lines (44 loc) · 1.52 KB
/
test.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
import json
import sqlite3
import sql
conn = sqlite3.connect("mistakes_collection.db")
print('Opened database successfully')
'''创建数据库'''
'''
try:
conn.execute(CREATE TABLE MISTAKE
(ID INTEGER PRIMARY KEY,
QUESTION TEXT UNIQUE,
ANSWER TEXT NOT NULL);)
print('Table created successfully')
except:
print('Table mistake already exists please ignore')
def get_right_answer(findQuiz,choose):
with open('question.hortor.net/question/bat/findQuiz', encoding='utf-8') as findQuiz,\
open('question.hortor.net/question/bat/choose', encoding='utf-8') as choose:
dit = json.load(findQuiz)
question = dit['data']['quiz']
choose = json.load(choose)['data']['option']
right_answer = dit['data']['options'][choose]
print('问题:%s' % question)
print('正确答案:%s' % right_answer)
#写入数据库
try:
sql = "insert into mistake(question,answer)values('%s','%s')" % (question,right_answer)
conn.execute(sql)
conn.commit()
print('Insert question successfully')
except:
print('This question already exists please ignore')
'''
cursor = conn.execute("select id,question,answer from mistake")
#sql = "delete from mistake where id =135 "
#conn.execute(sql)
#conn.commit()
for row in cursor:
print('ID = ', row[0])
print('QUESTION = ', row[1])
print('ANSWER = ', row[2])
print('Select Operation done successfully')
#with open('question.hortor.net/question/bat/findQuiz',encoding='utf-8') as f:
# print(json.load(f)['data']['quiz'],end='')