This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport pyzbar.py
120 lines (94 loc) · 2.79 KB
/
import pyzbar.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
import requests
import websocket
from threading import Thread
import time
import json
import Tools
import io
from PIL import Image
url = "wss://changjiang.yuketang.cn/wsapp/"
websoUrl = "wss://changjiang.yuketang.cn/wsapp/"
global qrQueryData
qrQueryData = json.dumps({"op": "requestlogin", "role": "web",
"version": 1.4, "type": "qrcode", "from": "web"})
def sendSignData(wait: int = 60):
global qrQueryData
while 1:
print("Sending... ")
wb.send(qrQueryData)
for i in range(wait, 0, -1):
print(f"\rwating... {Tools.color(str(i), 'green')}", end="")
time.sleep(1)
def showQRCode(qrc: bytes):
bt = io.BytesIO(qrc)
img = Image.open(bt)
img.show()
def getQRCode(url):
qrc = requests.get(url).content
return qrc
def onclose(wb):
print(wb)
def onopen(wb):
print("onopen")
def onmessage(wb, msg):
print("\nonmessage")
data = json.loads(msg)
match data["op"]:
case "requestlogin":
qrc = getQRCode(data["ticket"])
if len(qrc) > 1:
showQRCode(qrc)
else:
print("No QRCode Found")
case "loginsuccess":
pass
print("二维码时效:", data["expire_seconds"])
print(msg)
def onerror(wb, msg):
print("error")
print(msg)
wb = websocket.WebSocketApp(
url, on_open=onopen, on_message=onmessage, on_close=onclose, on_error=onerror)
Thread(target=wb.run_forever, daemon=True).start()
# def takeshit():
# print(1)
# time.sleep(5)
# Thread(target=takeshit, daemon=True).start()
# wb.run_forever()
# from PIL import Image, ImageOps
# import PIL
# import io
# import pyzbar.pyzbar as pyzbar
# import qrcode
# import qrcode_terminal
# import os
# os.system("")
# img = Image.open(r"C:\Users\moiiii\Desktop\tmp\RainClassroomAssitant\tmp\test0.png")
# # t = pyzbar.decode(img)
# # qr = qrcode.QRCode()
# # qr.add_data(t)
# # qr.make(fit=True)
# # res = qr.make_image()
# # res.save("qrc.png")
# white_block = '\033[0;37;47m '
# black_block = '\033[0;37;40m '
# new_line = '\033[0m\n'
# def terminalOutPut(qr:qrcode.QRCode):
# output = white_block*(qr.modules_count+2) + new_line
# for mn in qr.modules:
# output += white_block
# for m in mn:
# if m:
# output += black_block
# else:
# output += white_block
# output += white_block + new_line
# output += white_block*(qr.modules_count+2) + new_line
# return output
# # res.get_image()
# # open(r"C:\Users\moiiii\Desktop\tmp\RainClassroomAssitant\tmp\test0.png", "rb").read()
# # print(res.get_image())
# # print(Image.open(r"C:\Users\moiiii\Desktop\tmp\RainClassroomAssitant\tmp\test1.png"))
# if __name__ == "__main__":
# # pass
# print(terminalOutPut(qr))