forked from RishiNandha/Kossel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
180 lines (162 loc) · 3.72 KB
/
functions.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import csv
import random
from replit import db
def addtorepldb(deck,name,authorid):
print(deck,name,authorid)
print((str(authorid)+"_"+str(name)))
# db[(str(authorid)+str(name))]=deck
db[(str(authorid)+"_"+str(name))]=deck
def formatq(q,a,mode=0):
# print(q,a,mode,"in here")
if mode != 5:
arr=[q]
return arr
if mode == 5:
b=q.split(",")
c=a.split(",")
arr = []
n = []
ques_o = []
ans_o = []
for i in range(len(b)):
n.append(i)
random.shuffle(n)
for i in range(len(b)):
ques_o.append(b[n[i]].strip())
ans_o.append(c[n[i]].strip())
for i in range(len(b)):
arr.append(random.randint(0,1))
ques = []
ans = []
for i in range(len(b)):
if arr[i] == 0:
ques.append(ans_o[i])
ans.append(ques_o[i])
elif arr[i] == 1:
ques.append(ques_o[i])
ans.append(ans_o[i])
s =""
for i in range(len(ques)):
s+=ques[i]
if i != (len(ques)-1):
s+=", "
arr = [s,ans]
return arr
def format(l,mode=0):
if mode==0:
b=l.split("->")
for i in range(len(b)):
j=b[i].split("+")
for k in range(len(j)):
j[k]=j[k].strip()
for l in range(10):
j[k]=j[k].lstrip(str(l))
j[k]=j[k].lower()
j[k]=j[k].replace(" ", "")
b[i]=set(j)
return b
elif mode==2:
b=l.split(",")
b=[i.strip() for i in b]
b=[i.lower() for i in b]
b=set(b)
return b
elif mode==3:
b=l.split(",")
b=[i.strip() for i in b]
b=[i.lower() for i in b]
return b
elif mode ==5:
l=[i.strip() for i in l]
l=[i.lower() for i in l]
return l
elif mode == 6:
if "<" in l:
b=l.split("<")
b=[i.strip() for i in b]
b=[i.lower() for i in b]
return b
if ">" in l:
b=l.split(">")
b.reverse()
b=[i.strip() for i in b]
b=[i.lower() for i in b]
return b
else:
b=l.split()
b=[i.lower() for i in b]
b=set(b)
return b
def questions(name):
f=open("Decks/" +name+".csv","r")
a = csv.reader(f)
l=list()
for i in a:
if len(i)<5:
for j in range(5-len(i)):
i.append('')
if len(i[1])==0:
i[1]="Error: Answer was not given"
if len(i[0])>0:
if i[4] in [str(j) for j in range(10)]:
l.append([" "+i[0],i[1],i[2],i[3],int(i[4])])
else:
l.append([" "+i[0],i[1],i[2],i[3],0])
return l
def questions_repldb(file):
# f=open("Decks/" +name+".csv","r")
a = csv.reader(file)
l=list()
for i in a:
if len(i)<5:
for j in range(5-len(i)):
i.append('')
if len(i[1])==0:
i[1]="Error: Answer was not given"
if len(i[0])>0:
if i[4] in [str(j) for j in range(10)]:
l.append([" "+i[0],i[1],i[2],i[3],int(i[4])])
else:
l.append([" "+i[0],i[1],i[2],i[3],0])
return l
def find_num(a):
b = []
a = list(a)
c = ""
for i in range(len(a)):
a[i]=list(a[i])
for j in range(len(a[i])):
try:
b.append(int(a[i][j]))
except ValueError:
pass
# print(a)
for i in range(len(b)):
c+=str(b[i])
if len(c) == 0:
return 30
else:
return int(c)
def returnvalsofarray(a):
s = ""
for i in range(len(a)):
s+=a[i]
if i != (len(a) -1):
s+=","
return s
def export(name):
import csv
fields = []
rows = []
with open("Decks/"+name, 'r') as csvfile:
csvreader = csv.reader(csvfile)
fields = next(csvreader)
for row in csvreader:
rows.append(row)
f=open("anki.txt","w")
for row in rows[::-1]:
for i in range(len(row[2])):
if row[2][i]==";":
row[2]=row[2][:i]+"."+row[2][i+1:]
if len(row[0])!=0:
f.write(row[0]+r"<br>"+row[3]+";"+ row[1].lower()+r"<br>"+row[2]+"\n")