Package: hust-login
HustLoginA python-lib for authenticating HustPass@2023Faster, Easier, LighterAttention: HustPass login protocol underwent a major update on 2023/05/23, moving from DES to RSA, previous login libraries are now deprecated.Tutorials onBilibiliPlug-in for python-requestsHustAuthInstallingThe library has been made publicly available on PyPIhust_loginInstalling by a single line of command, and requirements will be automatically handled.pip install hust_loginAdditionally, you need to installtesseract-ocrback end:Win:download binary here, "3rd party Windows exe’s/installer" recommanded.Linux: runsudo apt install tesseract-ocrDocumentationhust_login.HustLogin(username, password, headers=None)PARAMETERS:username -- Username of pass.hust.edu.cn  e.g. U2022XXXXXpassword -- Password of pass.hust.edu.cnheaders  -- Headers you want to use, optional (the default header works fine)RETURNS:Arequests.Sessionobject that is already logged inuse it the same way you use requests, e.g.s=hust_login.HustPass('U2022XXXXX','YOUR-PASSWORD')ret=s.get(your_url)print(ret.text)hust_login.HustLogin(username, password, headers=None)PARAMETERS: Same as HustLoginRETURNS:A class that contains wrapped common functions like QueryElectricityBills, QueryCurriculum, QueryFreeRoom, etc.BE CREATIVE!!!DemoDemonstrating how to query the exam resultCODE:fromhust_loginimportHustPassfrombs4importBeautifulSoupwithHustPass('U2022XXXXX','YOUR-PASSWORD')ass:ret=s.get('http://hub.m.hust.edu.cn/cj/cjsearch/findcjinfo.action?xn=2022&xq=0')soup=BeautifulSoup(ret.content,'html.parser')forrowinsoup.find_all('tr'):forcolinrow.contents:print(col.text.strip(),end=" ")print("")It'srecommendedto callHustPassin thewithstatement, as shown.RESULT:setting up session...
captcha detected, trying to decaptcha...
decaptching...
encrypting u/p...
captcha_code:4608
posting login-form...
---HustPass Succeed---
 课程名称  课程学分  课程成绩  备注  
 微积分（一）（上）  5.5  90
 综合英语（一）  3.5  94
 线性代数  2.5  92
 工程制图（一）  2.5  98
 综合英语（二）  3.5  93
 微积分（一）（下）  5.5  94
  ...
  ...
  ...
 加权排名成绩  91.71
 必修课总学分  50.50
 公选课总学分  2.00
 总学分  52.5DevelopmentIf the lib outdated, try to make a pull request to get this lib working again!The js-scripts that enable encrypting and posting the login-form during regular login are publicly availablelogin_standar.js?v=20230523. My job was to translate the js into python and deal with the captcha code.Here are something worth mentioning if you are developing a newer version of the lib:Encrytion:PublicKey is encoded in base64, decode it first.The usr/pass you encrypted should be encoded in base64, and converted into the text instead of bytes. Look deeper into my code to see how it works.DecaptchaTheBytesIOmethod is used to convert byte-stream containing the gif into the file.Genius approach applied to combine and de-noise the 4-frame gif: As observed, thenumberpixels would appear in 3 frames at least, whilenoisepixels are less than 2. This provides a super accurate way to de-noise the picture. Here's the code clip, try to understand:img_merge=Image.new(mode='L',size=(width,height),color=255)forposin[(x,y)forxinrange(width)foryinrange(height)]:ifsum([img.getpixel(pos)<254forimginimg_list])>=3:img_merge.putpixel(pos,0)NetworkA common fake User-Agent is essential! HustPass has blocked python-requests's default User-Agent.