Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinTerry committed Jul 24, 2023
2 parents 25c75b3 + 4f03101 commit 8bca7f9
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 16 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/auto-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Automated Testing of Interface Availability

on:
push:
pull_request:
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools
pip install build
- name: Build package
run: python -m build

- name: upload artifacts
uses: actions/upload-artifact@v3
with:
path: dist/hust_login-*.whl

- name: cleanup artifacts
run: rm -r dist

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest] #[windows-latest, macos-latest, ubuntu-latest]

needs: build

steps:
- name: Download artifacts
uses: actions/download-artifact@v3

- name: Set up python
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd artifact
pip install hust_login-*.whl
python -m hust_login --autotest -U ${{ secrets.Uid }} -P ${{ secrets.Pwd }}
#- name: release
# uses: softprops/action-gh-release@v1
# with:
# files: "dist/**"
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Continuous Integration

on:
workflow_dispatch:

jobs:
build-whl:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest] #[windows-latest, macos-latest, ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools
pip install build
- name: Build package
run: python -m build

- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: hust_login_${{ matrix.os }}
path: dist/hust_login-*.whl

- name: cleanup artifacts
run: rm -r dist


8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Additionally, you need to install ```tesseract-ocr``` back end:
- Linux: run ```sudo apt install tesseract-ocr```

## Documentation
### **```hust_login.HustPass(username, password, headers=None)```**
### **```hust_login.HustLogin(username, password, headers=None)```**

PARAMETERS:
- username -- Username of pass.hust.edu.cn e.g. U2022XXXXX
Expand All @@ -38,6 +38,12 @@ Additionally, you need to install ```tesseract-ocr``` back end:
ret = s.get(your_url)
print(ret.text)
```
### **```hust_login.HustLogin(username, password, headers=None)```**

PARAMETERS: Same as HustLogin

RETURNS:
- A class that contains wrapped common functions like QueryElectricityBills, QueryCurriculum, QueryFreeRoom, etc.

> BE CREATIVE!!!

Expand Down
29 changes: 16 additions & 13 deletions README_ZH.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#HustPass
# HustPass
用于验证 HustPass@2023 的 python-lib

![HustPassLogo](https://pass.hust.edu.cn/cas/comm/image/logo-inside.png)

> 更快、更简单、更方便
注意:HustPass登录协议于2023年5月23日进行了重大更新,从DES迁移到RSA,以前的登录库现已不可使用。
Expand All @@ -15,17 +17,13 @@
pip install hust_login
```

此外,您需要安装```tesseract-ocr```后端:

依赖如下:
```
Pillow
pycryptodome
pytesseract
Requests
```
- Win:[在此处下载二进制文件](https://tesseract-ocr.github.io/tessdoc/Downloads.html),推荐“3rd party Windows exe’s/installer”。
- Linux:运行```sudo apt install tesseract-ocr```

## 文档
### **````hust_login.HustPass(用户名,密码)````**
### **```hust_login.HustLogin(用户名,密码,标头(可选)```**

参数:
- 用户名 -- pass.hust.edu.cn 的用户名 例如 U2022XXXXX
Expand All @@ -35,13 +33,17 @@ Requests
返回:
- 已登录的 **```requests.Session```** 对象
- 使用它的方式与使用请求的方式相同,例如
````python
```python
s = hust_login.HustPass('U2022XXXXX','您的密码')
ret = s.get(your_url)
print(ret.text)
````
```
### **```hust_login.HustPass(用户名,密码,标头(可选))```

> HustLogin接口已被弃用,请使用HustPass
参数:与HustLogin相同

返回:
- 一个类,包含QueryElectricityBills,QueryCurriculum,QueryFreeRoom等已包装的常用函数。

> 发挥创意!!!

Expand Down Expand Up @@ -98,13 +100,14 @@ Requests
- PublicKey采用base64编码,请先解码。
- 您加密的usr/pass应该以base64编码,并转换为文本而不是字节。 请更深入地研究我的代码,看看它是如何工作的。
- 解码器
- BytesIO”方法用于将包含 gif 的字节流转换为文件。
- 使用```BytesIO``` 方法将包含 gif 的字节流转换为文件。
- 采用 Genius 方法对 4 帧 gif 进行组合和去噪:据观察,**数量**像素至少会出现在 3 帧中,而**噪声**像素小于 2。这提供了一种超级准确的方法来对图片进行去噪。 这是代码片段,尝试理解:
```python
img_merge = Image.new(mode='L',size=(width,height),color=255)
for pos in [(x,y) for x in range(width) for y in range(height)]:
if sum([img.getpixel(pos) < 254 for img in img_list]) >= 3:
img_merge.putpixel(pos,0)
```
![org](images/captcha_code.gif) ![processed](images/captcha_code_processed.png)
- 网络
- 一个常见的假UA是必不可少的! HustPass 已阻止 python-requests 的默认UA
2 changes: 2 additions & 0 deletions hust_login/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .login import HustLogin, CheckLoginStatu
from . import curriculum # 课表相关归属在此命名空间下
from ._HustPass import HustPass
from . import free_room
from . import utility_bills as bills

from importlib.metadata import version, PackageNotFoundError

Expand Down
37 changes: 37 additions & 0 deletions hust_login/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import getopt

def main():
try:
opts, args = getopt.getopt(sys.argv[1:],'U:P:',['autotest'])
except:
print('USAGE: python -m hust_pass --autotest')

bad_param = False
autotest = False

for opt,arg in opts:
if opt in ['--autotest']:
autotest = True
elif opt =='-U':
Uid = arg
elif opt == '-P':
Pwd = arg
else:
bad_param = True
break

if bad_param:
print('USAGE: python -m hust_pass --autotest')
return
if autotest:
from .autotest import full_test
try:
code = full_test(Uid,Pwd)
except:
print('Test Failed')
return -1
return code

if __name__ == '__main__':
main()
22 changes: 22 additions & 0 deletions hust_login/autotest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from . import HustPass

def full_test(Uid,Pwd):
hpass = HustPass(Uid, Pwd)
try:
hpass.QueryCurriculum('2023-04-27')
hpass.QueryCurriculum(['2023-04-27','2023-03-27','2023-04-07'])
hpass.QueryCurriculum(8)
hpass.QueryCurriculum(('2023-04-01','2023-04-12'))
except:
return 10
try:
hpass.QueryElectricityBills('2023-04-27')
hpass.QueryElectricityBills(['2023-04-27','2023-03-27','2023-04-07'])
hpass.QueryElectricityBills(('2023-04-01','2023-04-12'))
except:
return 20
try:
hpass.QueryFreeRoom('2023-09-02')
except:
return 30
return 0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
setup_requires=['setuptools_scm'],
use_scm_version=True,
description='A python-lib for authenticating HustPass@2023',
author='MarvinTerry',
author_email='marvinterry2004@gmail.com',
author='MarvinTerry and Jackhr',
author_email='marvinterry2004@gmail.com and jj2460596@gmail.com',
url='https://github.com/MarvinTerry/HustLogin',
packages=['hust_login'],
license='MIT',
Expand Down

0 comments on commit 8bca7f9

Please sign in to comment.