-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
188 lines (172 loc) · 5.82 KB
/
tests.py
File metadata and controls
188 lines (172 loc) · 5.82 KB
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
181
182
183
184
185
186
187
188
import pandas as pd
from pymerkle import *
from hashlib import sha256
from PIL import Image, ImageDraw, ImageFont
import qrcode
from pyzbar.pyzbar import decode
from pymongo import MongoClient
client = MongoClient()
db = client.userdata.users
df = pd.read_excel('Students.xlsx')
z = []
arr = []
rem = len(df)
for i in range(len(df)):
rem -= 1
for j in range(len(list(df))):
z.append(df.iloc[i, j])
c = z
z = []
c[3] = str(c[3])
a = "+".join(c)
a_hash = sha256(a.encode()).hexdigest()
if len(arr) < 3:
arr.append(c)
else:
arr = []
arr.append(c)
if len(arr) == 3:
Mktree = MerkleTree(security=False, raw_bytes=False)
for a in arr:
a[3] = str(a[3])
ar = "+".join(a)
ar_hash = sha256(ar.encode()).hexdigest()
newuser = ({
"name": a[0],
"Matric No": a[1],
"Course": a[2],
"Year": a[3],
"Hash": ar_hash
})
db.insert_one(newuser)
Mktree.encryptRecord(ar)
for a in arr:
# print('')
img = Image.open('Cert_template.png')
qr = qrcode.QRCode(box_size=2)
qr.add_data([str(ar_hash), Mktree.get_commitment().decode("utf-8")], optimize=0)
qr.make()
test = qr.make_image(fill_color="black", back_color="white").convert('RGB')
img.paste(test, (330, 460))
I1 = ImageDraw.Draw(img)
font = ImageFont.truetype('font.ttf', 30)
I1.text((288, 156), a[0], font=font, fill=(0, 0, 0))
I1.text((288, 246), a[1], font=font, fill=(0, 0, 0))
I1.text((268, 326), a[2], font=font, fill=(0, 0, 0))
I1.text((348, 416), a[3], font=font, fill=(0, 0, 0))
img.save('uploads/certs/' + a[0] + '.png')
with open('structure', 'w') as f:
f.write(Mktree.__repr__())
Mktree.export('uploads/trees/' + Mktree.get_commitment().decode("utf-8") + '.json')
if rem < 2:
Mktree = MerkleTree(security=False, raw_bytes=False)
for a in arr:
print(a)
a[3] = str(a[3])
ar = "+".join(a)
ar_hash = sha256(ar.encode()).hexdigest()
newuser = ({
"name": a[0],
"Matric No": a[1],
"Course": a[2],
"Year": a[3],
"Hash": ar_hash
})
db.insert_one(newuser)
Mktree.encryptRecord(ar)
img = Image.open('Cert_template.png')
qr = qrcode.QRCode(box_size=2)
qr.add_data([str(ar_hash), Mktree.get_commitment().decode("utf-8")], optimize=0)
qr.make()
test = qr.make_image(fill_color="black", back_color="white").convert('RGB')
img.paste(test, (330, 460))
I1 = ImageDraw.Draw(img)
font = ImageFont.truetype('font.ttf', 30)
I1.text((288, 156), a[0], font=font, fill=(0, 0, 0))
I1.text((288, 246), a[1], font=font, fill=(0, 0, 0))
I1.text((268, 326), a[2], font=font, fill=(0, 0, 0))
I1.text((348, 416), a[3], font=font, fill=(0, 0, 0))
img.save('uploads/certs/' + a[0] + '.png')
with open('structure', 'w') as f:
f.write(Mktree.__repr__())
Mktree.export('uploads/trees/' + Mktree.get_commitment().decode("utf-8") + '.json')
print(Mktree)
# img = Image.open('Cert_template.png')
#
# I1 = ImageDraw.Draw(img)
#
# font = ImageFont.truetype('font.ttf', 30)
# I1.text((248, 156), "Adedokun Praise", font=font, fill=(0, 0, 0))
# I1.text((288, 246), "17/52HA013", font=font, fill=(0, 0, 0))
# I1.text((268, 326), "Computer Science", font=font, fill=(0, 0, 0))
# I1.text((348, 416), "2021", font=font, fill=(0, 0, 0))
#
# img.show()
# import xlsxwriter
#
# # Create a workbook and add a worksheet.
# workbook = xlsxwriter.Workbook('Students.xlsx')
# worksheet = workbook.add_worksheet()
#
# # Some data we want to write to the worksheet.
# expenses = (
# ['Name', 'Matric No', 'Department', 'Year'],
# ['John Doe', '17/52HA001', 'Computer Science', '2021'],
# ['Jane Doe', '17/52HA002', 'Computer Science', '2021'],
# ['Jim Doe', '17/52HA003', 'Computer Science', '2021'],
# ['Juliet Doe', '17/52HA004', 'Computer Science', '2021'],
# ['Tim Cook', '17/52HA005', 'Computer Science', '2021'],
# ['Tom Hanks', '17/52HA006', 'Computer Science', '2021'],
# ['Amy Tyler', '17/52HA007', 'Computer Science', '2021'],
# ['Rob Banks', '17/52HA008', 'Computer Science', '2021'],
# )
#
# # Start from the first cell. Rows and columns are zero indexed.
# row = 0
# col = 0
#
# # Iterate over the data and write it out row by row.
# for item, cost, c,v in (expenses):
# worksheet.write(row, col, item)
# worksheet.write(row, col + 1, cost)
# worksheet.write(row, col + 2, c)
# worksheet.write(row, col + 3, str(v))
# row += 1
#
#
# workbook.close()
# import pandas as pd
#
# df = pd.read_excel('Students.xlsx')
#
# z = []
# for i in range(len(df)):
# for j in range(len(list(df))):
# z.append(df.iloc[i,j])
# c = z
# z = []
# # print(c)
# img = Image.open('Cert_template.png')
#
# I1 = ImageDraw.Draw(img)
#
# font = ImageFont.truetype('font.ttf', 30)
# I1.text((248, 156), c[0], font=font, fill=(0, 0, 0))
# I1.text((288, 246), c[1], font=font, fill=(0, 0, 0))
# I1.text((268, 326), c[2], font=font, fill=(0, 0, 0))
# I1.text((348, 416), str(c[3]), font=font, fill=(0, 0, 0))
#
# # img.save(c[1] + '.png')
# img.show()
# c = []
# img = Image.open('Cert_template.png')
#
# I1 = ImageDraw.Draw(img)
#
# font = ImageFont.truetype('font.ttf', 30)
# I1.text((248, 156), z[0], font=font, fill=(0, 0, 0))
# I1.text((288, 246), z[1], font=font, fill=(0, 0, 0))
# I1.text((268, 326), z[2], font=font, fill=(0, 0, 0))
# I1.text((348, 416), z[3], font=font, fill=(0, 0, 0))
#
# img.show()