Skip to content

Commit

Permalink
提升验证码识别率至99.9%/修复时区问题/修复返校字段问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYang-xie committed Oct 27, 2021
1 parent 41b2e81 commit 9a5104e
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import time
import os
from json import loads as json_loads
from os import path as os_path, getenv
from sys import exit as sys_exit
Expand All @@ -10,10 +11,10 @@
import io
import numpy
from PIL import Image
from PIL import ImageEnhance


from requests import session, post

from requests import session, post, adapters
adapters.DEFAULT_RETRIES = 5

class Fudan:
"""
Expand All @@ -33,6 +34,7 @@ def __init__(self,
:param url_login: 登录页,默认服务为空
"""
self.session = session()
self.session.keep_alive = False
self.session.headers['User-Agent'] = self.UA
self.url_login = url_login
self.url_code = url_code
Expand Down Expand Up @@ -149,7 +151,12 @@ def check(self):
print("◉上一次提交地址为:", position['formattedAddress'])
# print("◉上一次提交GPS为", position["position"])
# print(last_info)

# 改为上海时区
os.environ['TZ'] = 'Asia/Shanghai'
time.tzset()
today = time.strftime("%Y%m%d", time.localtime())
print("◉今日日期为:", today)
if last_info["d"]["info"]["date"] == today:
print("\n*******今日已提交*******")
self.close()
Expand All @@ -158,10 +165,24 @@ def check(self):
self.last_info = last_info["d"]["oldInfo"]

def read_captcha(self, img_byte):
image = numpy.array(Image.open(io.BytesIO(img_byte)))
img = Image.open(io.BytesIO(img_byte)).convert('L')
enh_bri = ImageEnhance.Brightness(img)
new_img = enh_bri.enhance(factor=1.5)

image = numpy.array(new_img)
reader = easyocr.Reader(['en'])
result = reader.readtext(image, detail = 0)
horizontal_list, free_list = reader.detect(image, optimal_num_chars=4)
character = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
allow_list = list(character)
allow_list.extend(list(character.lower()))

result = reader.recognize(image,
allowlist=allow_list,
horizontal_list=horizontal_list[0],
free_list=free_list[0],
detail = 0)
return result[0]


def validate_code(self):
img = self.session.get(self.url_code).content
Expand Down Expand Up @@ -196,8 +217,8 @@ def checkin(self):
"province": province,
"city": city,
"area": " ".join((province, city, district)),
"sfzx": "1", # 是否在校
"fxyy": "", # 返校原因
#"sfzx": "1", # 是否在校
#"fxyy": "", # 返校原因
"code": code,

}
Expand All @@ -214,8 +235,6 @@ def checkin(self):
time.sleep(0.1)
if(json_loads(save.text)["e"] != 1):
break



def get_account():
"""
Expand Down Expand Up @@ -264,4 +283,4 @@ def get_account():
daily_fudan.checkin()
# 再检查一遍
daily_fudan.check()
daily_fudan.close(1)
daily_fudan.close(1)

0 comments on commit 9a5104e

Please sign in to comment.