-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcaptcha.py
More file actions
38 lines (29 loc) · 1 KB
/
captcha.py
File metadata and controls
38 lines (29 loc) · 1 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
import easyocr
import base64
from flask import Response
class Solver:
def __init__(self, imageb64):
self.imageb64 = imageb64
self.image = None
self.text = ""
async def getText(self):
reader = easyocr.Reader(['en'])
text = reader.readtext(image=self.image, detail=0,
decoder="greedy", adjust_contrast=1, contrast_ths=1)
self.text = text[0].upper()
async def b64ToImg(self):
decoded_data = base64.b64decode((self.imageb64))
self.image = decoded_data
async def formatToken(self):
notAllowedChars = '!@#$%^&*()_+=-}{\';:/.,?\\| '
for char in notAllowedChars:
if char in self.text:
self.text = self.text.replace(char, "")
return self.text
async def solve(self):
try:
await self.b64ToImg()
await self.getText()
return {"token": await self.formatToken()}
except:
return Response(status=500)