{"id":13729399,"url":"https://github.com/MarvinTerry/HustLogin","last_synced_at":"2025-05-08T01:32:28.667Z","repository":{"id":182078439,"uuid":"667916897","full_name":"MarvinTerry/HustLogin","owner":"MarvinTerry","description":"A python-lib for authenticating HustPass@2023","archived":false,"fork":false,"pushed_at":"2023-12-13T07:00:05.000Z","size":96,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-04T04:07:10.355Z","etag":null,"topics":["hust","login","python","requests","scrawler"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarvinTerry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-18T15:34:55.000Z","updated_at":"2024-09-13T04:56:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"dd317ff6-f4b3-4dc1-89e1-50354575d16e","html_url":"https://github.com/MarvinTerry/HustLogin","commit_stats":null,"previous_names":["marvinterry/hustlogin"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinTerry%2FHustLogin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinTerry%2FHustLogin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinTerry%2FHustLogin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinTerry%2FHustLogin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarvinTerry","download_url":"https://codeload.github.com/MarvinTerry/HustLogin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224688973,"owners_count":17353296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hust","login","python","requests","scrawler"],"created_at":"2024-08-03T02:00:59.661Z","updated_at":"2024-11-14T20:30:46.232Z","avatar_url":"https://github.com/MarvinTerry.png","language":"Python","funding_links":[],"categories":["小工具"],"sub_categories":["全校通用"],"readme":"# HustLogin\r\nA python-lib for authenticating HustPass@2023\r\n\r\n![HustPassLogo](https://pass.hust.edu.cn/cas/comm/image/logo-inside.png)\r\n\r\n\u003e Faster, Easier, Lighter\r\n\r\nAttention: HustPass login protocol underwent a major update on 2023/05/23, moving from DES to RSA, previous login libraries are now deprecated.\r\n\r\nTutorials on [Bilibili](https://www.bilibili.com/video/BV1bX4y1j7vR/)\r\n\r\nPlug-in for python-requests [HustAuth](https://github.com/MarvinTerry/HustAuth)\r\n\r\n## Installing\r\n\r\nThe library has been made publicly available on PyPI **[hust_login](https://pypi.org/project/hust-login/)**\r\n\r\nInstalling by a single line of command, and requirements will be automatically handled.\r\n\r\n```\r\npip install hust_login\r\n```\r\n\r\nAdditionally, you need to install ```tesseract-ocr``` back end:\r\n\r\n- Win: [download binary here](https://tesseract-ocr.github.io/tessdoc/Downloads.html), \"3rd party Windows exe’s/installer\" recommanded.\r\n- Linux: run ```sudo apt install tesseract-ocr```\r\n\r\n## Documentation\r\n### **```hust_login.HustLogin(username, password, headers=None)```**\r\n\r\n  PARAMETERS:\r\n  - username -- Username of pass.hust.edu.cn  e.g. U2022XXXXX\r\n  - password -- Password of pass.hust.edu.cn\r\n  - headers  -- Headers you want to use, optional (the default header works fine)\r\n\r\n  RETURNS:\r\n  - A **```requests.Session```** object that is already logged in\r\n    - use it the same way you use requests, e.g.\r\n      ```python\r\n      s = hust_login.HustPass('U2022XXXXX','YOUR-PASSWORD')\r\n      ret = s.get(your_url)\r\n      print(ret.text)\r\n      ```\r\n### **```hust_login.HustLogin(username, password, headers=None)```**\r\n\r\n  PARAMETERS: Same as HustLogin\r\n\r\n  RETURNS:\r\n  - A class that contains wrapped common functions like QueryElectricityBills, QueryCurriculum, QueryFreeRoom, etc.\r\n\r\n\u003e BE CREATIVE!!!\r\n\r\n## Demo\r\nDemonstrating how to query the exam result\r\n- CODE:\r\n  ```python\r\n  from hust_login import HustPass\r\n  from bs4 import BeautifulSoup\r\n  \r\n  with HustPass('U2022XXXXX','YOUR-PASSWORD') as s:\r\n      ret = s.get('http://hub.m.hust.edu.cn/cj/cjsearch/findcjinfo.action?xn=2022\u0026xq=0')\r\n      soup = BeautifulSoup(ret.content, 'html.parser')\r\n      for row in soup.find_all('tr'):\r\n          for col in row.contents:\r\n              print(col.text.strip(), end=\" \")\r\n          print(\"\")\r\n  ```\r\n  It's **recommended** to call ```HustPass``` in the ```with``` statement, as shown.\r\n- RESULT:\r\n  ```\r\n  setting up session...\r\n  captcha detected, trying to decaptcha...\r\n  decaptching...\r\n  encrypting u/p...\r\n  captcha_code:4608\r\n  posting login-form...\r\n  ---HustPass Succeed---\r\n   课程名称  课程学分  课程成绩  备注  \r\n   微积分（一）（上）  5.5  90\r\n   综合英语（一）  3.5  94\r\n   线性代数  2.5  92\r\n   工程制图（一）  2.5  98\r\n   综合英语（二）  3.5  93\r\n   微积分（一）（下）  5.5  94\r\n    ...\r\n    ...\r\n    ...\r\n   加权排名成绩  91.71\r\n   必修课总学分  50.50\r\n   公选课总学分  2.00\r\n   总学分  52.5\r\n  ```\r\n\r\n## Development\r\n\r\nIf the lib outdated, try to make a pull request to get this lib working again!\r\n\r\nThe js-scripts that enable encrypting and posting the login-form during regular login are publicly available [login_standar.js?v=20230523](https://pass.hust.edu.cn/cas/comm/js/login_standar.js?v=20230523). My job was to translate the js into python and deal with the captcha code.\r\n\r\nHere are something worth mentioning if you are developing a newer version of the lib:\r\n\r\n- Encrytion: \r\n  - PublicKey is encoded in base64, decode it first.\r\n  - 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.\r\n- Decaptcha\r\n  - The ```BytesIO``` method is used to convert byte-stream containing the gif into the file.\r\n  - Genius approach applied to combine and de-noise the 4-frame gif: As observed, the **number** pixels would appear in 3 frames at least, while **noise** pixels are less than 2. This provides a super accurate way to de-noise the picture. Here's the code clip, try to understand:\r\n    ```python\r\n    img_merge = Image.new(mode='L',size=(width,height),color=255)\r\n    for pos in [(x,y) for x in range(width) for y in range(height)]:\r\n        if sum([img.getpixel(pos) \u003c 254 for img in img_list]) \u003e= 3:\r\n            img_merge.putpixel(pos,0)\r\n    ``` \r\n    ![org](images/captcha_code.gif) ![processed](images/captcha_code_processed.png)\r\n  \r\n- Network\r\n  - A common fake User-Agent is essential! HustPass has blocked python-requests's default User-Agent.\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarvinTerry%2FHustLogin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMarvinTerry%2FHustLogin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarvinTerry%2FHustLogin/lists"}