-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_operations.py
116 lines (85 loc) · 3.08 KB
/
db_operations.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
# -*- coding: utf-8 -*-
import shelve
from utils.models import Qestion
from utils.SQlite3 import *
#Чтение данных из базы
'''
for key in db:
#Если ответ на ворос не установлен, то задаем этот вопрос
if db[key].correctAnswer is None:
print(key, '=>\n ', db[key].testName)
newObj = db[key]
newObj.findAnswer()
db[key] = newObj
db.close()
#Ответ на вопросы, eсли ответ на ворос не установлен, то задаем этот вопрос
cur, con = connect_or_create('upwork_test.db')
show_table("Qestion", cur)
for key in filter_table("Qestion", cur, "TEST", "CORRECT", ["Python test", "No answer"]):
print "N: ", key[0]
tempObj = Qestion(*(list(key))[1:])
print tempObj.moreOneAnswer
if tempObj.moreOneAnswer:
print "Bot: Attantion More one answer"
tempObj.findAnswer()
update_record("Qestion", cur, con, "CORRECT", '#~'.join(tempObj.correctAnswer), key[0])
####### Работа с SQL ########
#cur, con = connect_or_create('upwork.db')
#Создать таблицу
#create_table("Qestion", cur, "ID", "TEST", "QESTION", "ANSWERS", "CORRECT", "MOREONE")
#print parserModel(db['question_1'])
#Перешел из Shelve в SQL
recordsList = []
idCount = 0
for key in db:
tempList = parserModel(db[key])
tempList.append(False)
tempList.insert(0,idCount)
recordsList.append(tempList)
idCount+=1
#Записать в базу запись
print idCount, "TOTAL"
save_records("Qestion", cur, con, recordsList)
#Показать результат
result = show_table("Qestion", cur, 'CORRECT')
print len(result)
for i in result:
print i
#Изменить значения в базе
idCount = 0
for key in db:
#print "#~".join(db[key].correctAnswer)
temp_res = "#~".join(db[key].correctAnswer)
update_record("Qestion", cur, con, "CORRECT", temp_res, idCount)
idCount+=1
#Показать результат
#result = show_table("Qestion", cur, "CORRECT")
#print len(result)
#for i in result:
# print i
#Запись результатов в файл
cur, con = connect_or_create('upwork.db')
'''
cur, con = connect_or_create('data/database.db')
delete_record("Qestion", cur, con, "ID", [194])
for i in filter_table("Qestion", cur, "TEST", None, ["Python Test"]):
if i[0]==1720 or i[0]==194:
print i
#update_record("Qestion", cur, con, "TEST", "Python Test", i[0])
#filterResult = filter_table("Qestion", cur, "TEST", None, ["Python test"])
#print create_table("User", cur, con, USERNAME = "TEXT", EMAIL = "TEXT", PASSWORD = "TEXT")
#print saveInFile(filter_table("Qestion", cur, "TEST", None, ["Python test"]))
"""
for (type, name) in showInfo('Qestion', cur):
if type == u"BOOLEAN":
print 'bool'
else:
print 'not bool'
"""
#Изменить значения в базе
#idCount = 0
#for key in filter_table("Qestion", cur, "TEST", None, ["Python test"]):
#print "#~".join(db[key].correctAnswer)
# if key[4].find('#~')!=-1:
# update_record("Qestion", cur, con, "MOREONE", True, idCount)
# idCount+=1