Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23703583c6 | |||
| 8b68d01fce | |||
| 43a05287c3 | |||
| 23bb87026b | |||
| 458ae8a8cc | |||
| 902785d94a | |||
| 4704d8c908 |
8
.idea/.gitignore
vendored
8
.idea/.gitignore
vendored
@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/../../../../../:\Dev\PycharmProjects\Yuanshen\.idea/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Yuanshen)" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/Yuanshen.iml" filepath="$PROJECT_DIR$/.idea/Yuanshen.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
37
index.py
37
index.py
@ -1,12 +1,16 @@
|
|||||||
'''
|
"""
|
||||||
|
cron: 10 12 * * * *
|
||||||
|
new Env('米游社原神签到');
|
||||||
|
|
||||||
@File : genshin.py
|
@File : genshin.py
|
||||||
@Github : https://github.com/y1ndan/genshin-impact-helper
|
@Github : https://github.com/y1ndan/genshin-impact-helper
|
||||||
@Last modified by : y1ndan
|
@Last modified by : y1ndan
|
||||||
@Last modified time : 2021-01-13 11:10:30
|
@Last modified time : 2021-01-13 11:10:30
|
||||||
'''
|
"""
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
@ -17,6 +21,7 @@ from requests.exceptions import HTTPError
|
|||||||
|
|
||||||
from settings import log, CONFIG
|
from settings import log, CONFIG
|
||||||
from notify import Notify
|
from notify import Notify
|
||||||
|
from ql_api import get_envs, disable_env, post_envs, put_envs
|
||||||
|
|
||||||
|
|
||||||
def hexdigest(text):
|
def hexdigest(text):
|
||||||
@ -79,7 +84,7 @@ class Roles(Base):
|
|||||||
continue
|
continue
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
log.error(
|
log.error(
|
||||||
'Wrong response to get game roles, retry %s time(s)...'% i)
|
'Wrong response to get game roles, retry %s time(s)...' % i)
|
||||||
log.error('response is %s' % error)
|
log.error('response is %s' % error)
|
||||||
continue
|
continue
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
@ -93,7 +98,7 @@ class Roles(Base):
|
|||||||
'Maximum retry times have been reached, error is %s ' % error)
|
'Maximum retry times have been reached, error is %s ' % error)
|
||||||
raise Exception(error)
|
raise Exception(error)
|
||||||
if response.get(
|
if response.get(
|
||||||
'retcode', 1) != 0 or response.get('data', None) is None:
|
'retcode', 1) != 0 or response.get('data', None) is None:
|
||||||
raise Exception(response['message'])
|
raise Exception(response['message'])
|
||||||
|
|
||||||
log.info('账号信息获取完毕')
|
log.info('账号信息获取完毕')
|
||||||
@ -119,7 +124,7 @@ class Sign(Base):
|
|||||||
def get_header(self):
|
def get_header(self):
|
||||||
header = super(Sign, self).get_header()
|
header = super(Sign, self).get_header()
|
||||||
header.update({
|
header.update({
|
||||||
'x-rpc-device_id':str(uuid.uuid3(
|
'x-rpc-device_id': str(uuid.uuid3(
|
||||||
uuid.NAMESPACE_URL, self._cookie)).replace('-', '').upper(),
|
uuid.NAMESPACE_URL, self._cookie)).replace('-', '').upper(),
|
||||||
# 1: ios
|
# 1: ios
|
||||||
# 2: android
|
# 2: android
|
||||||
@ -145,7 +150,7 @@ class Sign(Base):
|
|||||||
# cn_qd01: 世界树
|
# cn_qd01: 世界树
|
||||||
self._region_list = [(i.get('region', 'NA')) for i in role_list]
|
self._region_list = [(i.get('region', 'NA')) for i in role_list]
|
||||||
self._region_name_list = [(i.get('region_name', 'NA'))
|
self._region_name_list = [(i.get('region_name', 'NA'))
|
||||||
for i in role_list]
|
for i in role_list]
|
||||||
self._uid_list = [(i.get('game_uid', 'NA')) for i in role_list]
|
self._uid_list = [(i.get('game_uid', 'NA')) for i in role_list]
|
||||||
|
|
||||||
log.info('准备获取签到信息...')
|
log.info('准备获取签到信息...')
|
||||||
@ -228,7 +233,21 @@ class Sign(Base):
|
|||||||
return CONFIG.MESSGAE_TEMPLATE
|
return CONFIG.MESSGAE_TEMPLATE
|
||||||
|
|
||||||
|
|
||||||
def main_handler(event, context):
|
# 获取要执行兑换的cookie
|
||||||
|
def get_cookie():
|
||||||
|
ck_list = []
|
||||||
|
cookie = None
|
||||||
|
cookies = get_envs("MIHOYO_COOKIE")
|
||||||
|
for ck in cookies:
|
||||||
|
if ck.get('status') == 0:
|
||||||
|
ck_list.append(ck.get("value"))
|
||||||
|
if len(ck_list) == 0:
|
||||||
|
print('共配置{}条CK,请添加环境变量,或查看环境变量状态'.format(len(ck_list)))
|
||||||
|
return ck_list
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# def main_handler(event, context):
|
||||||
log.info('任务开始')
|
log.info('任务开始')
|
||||||
notify = Notify()
|
notify = Notify()
|
||||||
msg_list = []
|
msg_list = []
|
||||||
@ -237,7 +256,7 @@ def main_handler(event, context):
|
|||||||
# 此处填米游社的COOKIE
|
# 此处填米游社的COOKIE
|
||||||
# 注: Github Actions用户请到Settings->Secrets里设置,Name=COOKIE,Value=<获取的值>
|
# 注: Github Actions用户请到Settings->Secrets里设置,Name=COOKIE,Value=<获取的值>
|
||||||
# 多个账号的COOKIE值之间用 # 号隔开,例如: 1#2#3#4
|
# 多个账号的COOKIE值之间用 # 号隔开,例如: 1#2#3#4
|
||||||
COOKIE = ''
|
COOKIE = "#".join(get_cookie())
|
||||||
|
|
||||||
if os.environ.get('COOKIE', '') != '':
|
if os.environ.get('COOKIE', '') != '':
|
||||||
COOKIE = os.environ['COOKIE']
|
COOKIE = os.environ['COOKIE']
|
||||||
@ -261,4 +280,4 @@ def main_handler(event, context):
|
|||||||
if ret != 0:
|
if ret != 0:
|
||||||
log.error('异常退出')
|
log.error('异常退出')
|
||||||
exit(ret)
|
exit(ret)
|
||||||
log.info('任务结束')
|
log.info('任务结束')
|
||||||
|
|||||||
44
notify.py
44
notify.py
@ -4,16 +4,16 @@
|
|||||||
@Last modified by : y1ndan
|
@Last modified by : y1ndan
|
||||||
@Last modified time : 2021-01-13 11:01:10
|
@Last modified time : 2021-01-13 11:01:10
|
||||||
'''
|
'''
|
||||||
|
import base64
|
||||||
|
import hashlib
|
||||||
|
import hmac
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import hmac
|
from urllib import parse
|
||||||
import hashlib
|
|
||||||
import base64
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError
|
||||||
from urllib import parse
|
|
||||||
|
|
||||||
from settings import log
|
from settings import log
|
||||||
|
|
||||||
@ -121,6 +121,20 @@ class Notify(object):
|
|||||||
# 注: Github Actions用户请到Settings->Secrets里设置,Name=PUSH_PLUS_USER,Value=<获取的值>
|
# 注: Github Actions用户请到Settings->Secrets里设置,Name=PUSH_PLUS_USER,Value=<获取的值>
|
||||||
PUSH_PLUS_USER = ''
|
PUSH_PLUS_USER = ''
|
||||||
|
|
||||||
|
|
||||||
|
# ============================== go-cqhttp ====================================
|
||||||
|
# 官方文档:https://docs.go-cqhttp.org/guide/quick_start.html#使用
|
||||||
|
# GO_CQHTTP_URL 服务器地址
|
||||||
|
# GO_CQHTTP_TOKEN 你的token
|
||||||
|
# GO_CQHTTP_GROUP 参数
|
||||||
|
# GO_CQHTTP_API 接口名
|
||||||
|
|
||||||
|
GO_CQHTTP_URL = ''
|
||||||
|
GO_CQHTTP_TOKEN = ''
|
||||||
|
GO_CQHTTP_GROUP_NO = ''
|
||||||
|
GO_CQHTTP_API = ''
|
||||||
|
|
||||||
|
|
||||||
if os.environ.get('PUSH_PLUS_TOKEN', '') != '':
|
if os.environ.get('PUSH_PLUS_TOKEN', '') != '':
|
||||||
PUSH_PLUS_TOKEN = os.environ['PUSH_PLUS_TOKEN']
|
PUSH_PLUS_TOKEN = os.environ['PUSH_PLUS_TOKEN']
|
||||||
if os.environ.get('PUSH_PLUS_USER', '') != '':
|
if os.environ.get('PUSH_PLUS_USER', '') != '':
|
||||||
@ -314,6 +328,27 @@ class Notify(object):
|
|||||||
log.info('您未配置pushplus推送所需的PUSH_PLUS_TOKEN,取消pushplus推送')
|
log.info('您未配置pushplus推送所需的PUSH_PLUS_TOKEN,取消pushplus推送')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def cqhttp(self, text, status, desp):
|
||||||
|
if Notify.GO_CQHTTP_URL != '':
|
||||||
|
url = '{}{}'.format(Notify.GO_CQHTTP_URL, Notify.GO_CQHTTP_API)
|
||||||
|
data = {
|
||||||
|
'access_token': Notify.GO_CQHTTP_TOKEN,
|
||||||
|
'message': '{} {}\n\n{}'.format(text, status, desp),
|
||||||
|
'group_id': Notify.GO_CQHTTP_GROUP_NO
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
response = self.to_python(requests.get(url, params=data).text)
|
||||||
|
except Exception as e:
|
||||||
|
log.error(e)
|
||||||
|
raise HTTPError
|
||||||
|
else:
|
||||||
|
if response['status'] == 'ok':
|
||||||
|
log.info('go-cqhttp推送成功')
|
||||||
|
else:
|
||||||
|
log.error('go-cqhttp推送失败:\n{}'.format(response))
|
||||||
|
else:
|
||||||
|
log.info('您未配置go-cqhttp推送所需的GO_CQHTTP_URL,取消go-cqhttp推送')
|
||||||
|
pass
|
||||||
def send(self, **kwargs):
|
def send(self, **kwargs):
|
||||||
app = '原神签到小助手'
|
app = '原神签到小助手'
|
||||||
status = kwargs.get('status', '')
|
status = kwargs.get('status', '')
|
||||||
@ -332,6 +367,7 @@ class Notify(object):
|
|||||||
self.wwBot(app, status, msg)
|
self.wwBot(app, status, msg)
|
||||||
self.iGot(app, status, msg)
|
self.iGot(app, status, msg)
|
||||||
self.pushPlus(app, status, msg)
|
self.pushPlus(app, status, msg)
|
||||||
|
self.cqhttp(app, status, msg)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
100
ql_api.py
Normal file
100
ql_api.py
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
ql_auth_path = '/ql/config/auth.json'
|
||||||
|
# ql_auth_path = r'D:\Docker\ql\config\auth.json'
|
||||||
|
ql_url = 'http://localhost:5600'
|
||||||
|
|
||||||
|
|
||||||
|
def __get_token() -> str or None:
|
||||||
|
with open(ql_auth_path, 'r', encoding='utf-8') as f:
|
||||||
|
j_data = json.load(f)
|
||||||
|
return j_data.get('token')
|
||||||
|
|
||||||
|
|
||||||
|
def __get__headers() -> dict:
|
||||||
|
headers = {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json;charset=UTF-8',
|
||||||
|
'Authorization': 'Bearer ' + __get_token()
|
||||||
|
}
|
||||||
|
return headers
|
||||||
|
|
||||||
|
|
||||||
|
# 查询环境变量
|
||||||
|
def get_envs(name: str = None) -> list:
|
||||||
|
params = {
|
||||||
|
't': int(time.time() * 1000)
|
||||||
|
}
|
||||||
|
if name is not None:
|
||||||
|
params['searchValue'] = name
|
||||||
|
res = requests.get(ql_url + '/api/envs', headers=__get__headers(), params=params)
|
||||||
|
j_data = res.json()
|
||||||
|
if j_data['code'] == 200:
|
||||||
|
return j_data['data']
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
# 新增环境变量
|
||||||
|
def post_envs(name: str, value: str, remarks: str = None) -> list:
|
||||||
|
params = {
|
||||||
|
't': int(time.time() * 1000)
|
||||||
|
}
|
||||||
|
data = [{
|
||||||
|
'name': name,
|
||||||
|
'value': value
|
||||||
|
}]
|
||||||
|
if remarks is not None:
|
||||||
|
data[0]['remarks'] = remarks
|
||||||
|
res = requests.post(ql_url + '/api/envs', headers=__get__headers(), params=params, json=data)
|
||||||
|
j_data = res.json()
|
||||||
|
if j_data['code'] == 200:
|
||||||
|
return j_data['data']
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
# 修改环境变量
|
||||||
|
def put_envs(_id: str, name: str, value: str, remarks: str = None) -> bool:
|
||||||
|
params = {
|
||||||
|
't': int(time.time() * 1000)
|
||||||
|
}
|
||||||
|
data = {
|
||||||
|
'name': name,
|
||||||
|
'value': value,
|
||||||
|
'_id': _id
|
||||||
|
}
|
||||||
|
if remarks is not None:
|
||||||
|
data['remarks'] = remarks
|
||||||
|
res = requests.put(ql_url + '/api/envs', headers=__get__headers(), params=params, json=data)
|
||||||
|
j_data = res.json()
|
||||||
|
if j_data['code'] == 200:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# 禁用环境变量
|
||||||
|
def disable_env(_id: str) -> bool:
|
||||||
|
params = {
|
||||||
|
't': int(time.time() * 1000)
|
||||||
|
}
|
||||||
|
data = [_id]
|
||||||
|
res = requests.put(ql_url + '/api/envs/disable', headers=__get__headers(), params=params, json=data)
|
||||||
|
j_data = res.json()
|
||||||
|
if j_data['code'] == 200:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# 启用环境变量
|
||||||
|
def enable_env(_id: str) -> bool:
|
||||||
|
params = {
|
||||||
|
't': int(time.time() * 1000)
|
||||||
|
}
|
||||||
|
data = [_id]
|
||||||
|
res = requests.put(ql_url + '/api/envs/enable', headers=__get__headers(), params=params, json=data)
|
||||||
|
j_data = res.json()
|
||||||
|
if j_data['code'] == 200:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
Loading…
Reference in New Issue
Block a user