Skip to content

Commit

Permalink
API改变
Browse files Browse the repository at this point in the history
API改变
  • Loading branch information
tianzhengs committed Oct 10, 2022
1 parent 007caed commit 9f17120
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from study import study
from utility import md5


def getAccounts():
result = []
Expand Down
21 changes: 15 additions & 6 deletions study.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ def study(username, password, ua):
print('登入失败,退出')
return 0

haveLearned = bjySession.get('https://m.bjyouth.net/dxx/my-integral?type=2&page=1&limit=15').json()
orgIdTemp = ''
orgPattern = re.compile(r'\(|(\s*(\d+)\s*)|\)') # 组织id应该是被括号包的
rTemp = orgPattern.search(haveLearned['data'][0]['orgname'])
if rTemp:
orgID = rTemp.group(1)
else:
haveLearned = bjySession.get('https://m.bjyouth.net/dxx/my-study?page=1&limit=15&year=2022').json()

orgID = ""
try:
orgIdTemp = orgPattern.search(haveLearned['data'][0]['orgname'])
orgID = orgIdTemp.group(1)
except:
print('获取组织id-2')
orgIdTemp = orgPattern.search(bjySession.get('https://m.bjyouth.net/dxx/my').json()['data']['org'])
if orgIdTemp:
orgID = orgIdTemp.group(1)

if not orgID:
orgID = '172442'
print(f"无法从{haveLearned['data'][0]['orgname']}中获取orgID")
print(f"无法获取orgID")

if f"学习课程:《{title}》" in list(map(lambda x: x['text'], haveLearned['data'])):
print(f'{title} 在运行前已完成,退出')
Expand Down
7 changes: 6 additions & 1 deletion utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Crypto.PublicKey import RSA
from PIL import Image

from ddddocr import DdddOcr


Expand All @@ -14,12 +15,14 @@ def encrypt(t):
cipher_text = b64encode(cipher.encrypt(t.encode()))
return cipher_text.decode()


def md5(s):
import hashlib
m = hashlib.md5()
m.update(s.encode())
return m.hexdigest()


def cap_recognize(cap):
return DdddOcr().classification(denoise(cap))

Expand Down Expand Up @@ -53,9 +56,11 @@ def denoise(cap):
img.save(buf, format='PNG')
return buf.getvalue()


if __name__ == '__main__':
import requests
import re

bjySession = requests.session()
bjySession.timeout = 5 # set session timeout
touch = bjySession.get(url="https://m.bjyouth.net/site/login")
Expand All @@ -68,4 +73,4 @@ def denoise(cap):
img.show()

img = Image.open(BytesIO(cap2))
img.show()
img.show()

0 comments on commit 9f17120

Please sign in to comment.