-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_qr.py
63 lines (45 loc) · 1.3 KB
/
make_qr.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
# Code to get the qrcodes for different registration numbers,
# Save it and enter the required values in database
import requests
import shutil
import json
import hashlib
import MySQLdb as db
import os
# Credentials
HOST = "your_host"
PORT = "your_port"
USER = "your_user"
PASSWORD = "your_password"
DB = "your_db"
# Loop for the no of qr codes required (ex:500 here)
for i in range(1,501):
# Basic info
# start
REG_NO="1801"+"{0:0=3d}".format(i)
CODE = hashlib.md5(REG_NO.encode('utf-8')).hexdigest()
BASE="http://ca.e-summit-iitbbs.com/register/register.php?p="
URL_DATA = BASE+CODE
#print(URL_DATA)
# end
# API endpoint (using get method)
# start
URL = "http://api.qrserver.com/v1/create-qr-code/"
PARAMS = {
'data':URL_DATA,
'size':"300x300",
'color':"0-0-255"
}
import os
if not os.path.exists('qrcodes'):
os.makedirs('qrcodes')
r = requests.get(url = URL, params = PARAMS, allow_redirects=True)
open('qrcodes/'+REG_NO+".png", 'wb').write(r.content)
# end
# Making an sql insert command
# start
sql_query="INSERT INTO `qr_code`(`id`, `normal_value`, `hashed`) VALUES (\'NULL\',\'%s\',\'%s\');" % (REG_NO, CODE)
print (sql_query)
#end
# Could also write a piece of code to connect to remote sql and run the command.
# Else you can copy paste the ouput of the code later.