-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifiqr.py
109 lines (95 loc) · 2.72 KB
/
wifiqr.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
import qrcode
import time
import os
from os.path import isfile, join, dirname
import platform
from datetime import datetime
import sys
import subprocess
import io
# Static
ans = 1
myos = platform.system()
export_path = '/export'
def title():
with open('title.txt', 'r') as f:
for line in f:
print(line.strip())
time.sleep(0.1)
def openimage(path):
imageViewerFromCommandLine = {'linux':'xdg-open',
'win32':'explorer',
'darwin':'open'}[sys.platform]
subprocess.run([imageViewerFromCommandLine, path])
def terminal_qr(mqr):
qr = qrcode.QRCode()
qr.add_data(mqr)
h = io.StringIO()
qr.print_ascii(out=h)
h.seek(0)
print(h.read())
def viewqr():
dir_path = str(dirname(os.path.realpath(__file__))) + '\export\\'
filenames = next(os.walk(dir_path), (None, None, []))[2]
o = 0
while o < len(filenames):
print('['+str(o)+'] '+filenames[o])
o += 1
ch = input('\nSelect number: ')
if ch.isnumeric() == 0 or len(filenames)-1<int(ch):
print('Please enter an option from the list')
filepath = dir_path + filenames[int(ch)]
print(filepath)
terminal_qr(filepath)
def options():
print('\nWhat would you like to do?\n\n[0] Generate new WiFiQR\n[1] View existing WiFiQR')
opt = input('\nChoose option: ')
optlist = {'0':make_qr,
'1':viewqr}
try:
function = optlist[opt]
except KeyError:
raise ValueError('invalid input')
function()
def make_qr():
date = datetime.now().strftime('%Y%m%d_%H-%M-%S')
ssid = str(input('SSID: '))
pword = str(input('Password: '))
filename = str(input('File Name: ') + ' ' + str(date) + '.png')
wificode = 'WIFI:T:WPA;P:' + pword + ';S:' + ssid + ';H:false'
img = qrcode.make(wificode)
type(img)
savestr = str('export/'+filename)
img.save(savestr)
terminal_qr(savestr)
time.sleep(0.1)
op = input('Would you like to open the Generated QR Code? (Y,N): ')
f_op = op.upper().replace(' ','')
if f_op == 'Y':
if sys.platform == 'win32':
filenamedir = str('export\\'+filename)
else:
filenamedir = str('export/'+filename)
openimage(filenamedir)
def clear():
if myos == 'Windows':
os.system('cls')
else:
os.system('clear')
def loop_func():
global ans
loop_ans = input('Would you like to start over? (Y,N): ')
f_loop_ans = loop_ans.upper().replace(' ','')
if f_loop_ans == 'Y':
ans = 1
else:
ans = 0
def run():
title()
options()
clear()
loop_func()
clear()
if __name__ == '__main__':
while ans == 1:
run()