-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrgen.py
85 lines (66 loc) · 2.14 KB
/
qrgen.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
# https://pypi.org/project/qrcode/
# https://en.wikipedia.org/wiki/QR_code
# https://github.com/zxing/zxing/wiki/Barcode-Contents
import qrcode
import math
import argparse
# Notes:
# - Pre-escape your SSID and/or password if you have any special characters in them. Special characters \ ; , " : should be escaped with a backslash \.
# - Doesn't support WPA2-EAP.
# - WEP and hidden SSIDs are now supported but untested.
# - Always using low error correct for the QR code.
# - Should scale the QR code up in size if needed.
def ConvertLine(data, start, end):
i = start
count = 0
c = 0
while i < end:
while data[i]:
i+=1
x=i
y=j
while i<end and not mylist[i]:
i+=1
c+=1
f.write(str(x-start)+','+str(y)+','+str(c) + ' , ')
c = 0
count+=1
return count
parser = argparse.ArgumentParser(description='Generate data for QR code for provided Wifi network into scad file.')
parser.add_argument('SSID', help='The WiFi networks SSID.')
parser.add_argument('Password', help='The password for that SSDID.')
parser.add_argument("--wep", help="Set if using WEP security. Defaults to WPA.", action="store_true")
parser.add_argument("--hidden", help="Set if the SSID in question is hidden.", action="store_true")
parser.add_argument("--quiet", help="Don't output anything to command line.", action="store_true")
args = parser.parse_args()
security = "WPA"
hidden = ""
if args.wep:
security = "WEP"
if args.hidden:
hidden = "H:true"
data = "WIFI:T:" + security + ";S:" + args.SSID + ";P:" + args.Password + ";" + hidden + ";"
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=1,
border=0,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
mylist = list(img.getdata())
size = int(math.sqrt(len(mylist)))
if not args.quiet:
print(data)
print(size, 'x', size)
f = open("data.scad", "w")
f.write('ssidname = "' + args.SSID + '";\n')
f.write("qrsize = " + str(size) + ";\n")
f.write("qrdata2 = [")
count = 0;
for j in range(0, size):
count += ConvertLine(mylist, j*size, (j+1)*size)
f.write("];\n")
f.write("qrdata2count = " + str(count) + ";")
f.close()