Compare commits
No commits in common. "qinglong" and "master" have entirely different histories.
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 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/
|
||||
10
.idea/Yuanshen.iml
Normal file
10
.idea/Yuanshen.iml
Normal file
@ -0,0 +1,10 @@
|
||||
<?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>
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?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>
|
||||
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?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>
|
||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?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,16 +1,12 @@
|
||||
"""
|
||||
cron: 10 12 * * * *
|
||||
new Env('米游社原神签到');
|
||||
|
||||
'''
|
||||
@File : genshin.py
|
||||
@Github : https://github.com/y1ndan/genshin-impact-helper
|
||||
@Last modified by : y1ndan
|
||||
@Last modified time : 2021-01-13 11:10:30
|
||||
"""
|
||||
'''
|
||||
import hashlib
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import time
|
||||
import uuid
|
||||
@ -21,7 +17,6 @@ from requests.exceptions import HTTPError
|
||||
|
||||
from settings import log, CONFIG
|
||||
from notify import Notify
|
||||
from ql_api import get_envs, disable_env, post_envs, put_envs
|
||||
|
||||
|
||||
def hexdigest(text):
|
||||
@ -84,7 +79,7 @@ class Roles(Base):
|
||||
continue
|
||||
except KeyError as 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)
|
||||
continue
|
||||
except Exception as error:
|
||||
@ -98,7 +93,7 @@ class Roles(Base):
|
||||
'Maximum retry times have been reached, error is %s ' % error)
|
||||
raise Exception(error)
|
||||
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'])
|
||||
|
||||
log.info('账号信息获取完毕')
|
||||
@ -124,7 +119,7 @@ class Sign(Base):
|
||||
def get_header(self):
|
||||
header = super(Sign, self).get_header()
|
||||
header.update({
|
||||
'x-rpc-device_id': str(uuid.uuid3(
|
||||
'x-rpc-device_id':str(uuid.uuid3(
|
||||
uuid.NAMESPACE_URL, self._cookie)).replace('-', '').upper(),
|
||||
# 1: ios
|
||||
# 2: android
|
||||
@ -150,7 +145,7 @@ class Sign(Base):
|
||||
# cn_qd01: 世界树
|
||||
self._region_list = [(i.get('region', 'NA')) for i in role_list]
|
||||
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]
|
||||
|
||||
log.info('准备获取签到信息...')
|
||||
@ -233,21 +228,7 @@ class Sign(Base):
|
||||
return CONFIG.MESSGAE_TEMPLATE
|
||||
|
||||
|
||||
# 获取要执行兑换的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):
|
||||
def main_handler(event, context):
|
||||
log.info('任务开始')
|
||||
notify = Notify()
|
||||
msg_list = []
|
||||
@ -256,7 +237,7 @@ if __name__ == '__main__':
|
||||
# 此处填米游社的COOKIE
|
||||
# 注: Github Actions用户请到Settings->Secrets里设置,Name=COOKIE,Value=<获取的值>
|
||||
# 多个账号的COOKIE值之间用 # 号隔开,例如: 1#2#3#4
|
||||
COOKIE = "#".join(get_cookie())
|
||||
COOKIE = ''
|
||||
|
||||
if os.environ.get('COOKIE', '') != '':
|
||||
COOKIE = os.environ['COOKIE']
|
||||
@ -280,4 +261,4 @@ if __name__ == '__main__':
|
||||
if ret != 0:
|
||||
log.error('异常退出')
|
||||
exit(ret)
|
||||
log.info('任务结束')
|
||||
log.info('任务结束')
|
||||
44
notify.py
44
notify.py
@ -4,16 +4,16 @@
|
||||
@Last modified by : y1ndan
|
||||
@Last modified time : 2021-01-13 11:01:10
|
||||
'''
|
||||
import base64
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from urllib import parse
|
||||
import hmac
|
||||
import hashlib
|
||||
import base64
|
||||
|
||||
import requests
|
||||
from requests.exceptions import HTTPError
|
||||
from urllib import parse
|
||||
|
||||
from settings import log
|
||||
|
||||
@ -121,20 +121,6 @@ class Notify(object):
|
||||
# 注: Github Actions用户请到Settings->Secrets里设置,Name=PUSH_PLUS_USER,Value=<获取的值>
|
||||
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', '') != '':
|
||||
PUSH_PLUS_TOKEN = os.environ['PUSH_PLUS_TOKEN']
|
||||
if os.environ.get('PUSH_PLUS_USER', '') != '':
|
||||
@ -328,27 +314,6 @@ class Notify(object):
|
||||
log.info('您未配置pushplus推送所需的PUSH_PLUS_TOKEN,取消pushplus推送')
|
||||
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):
|
||||
app = '原神签到小助手'
|
||||
status = kwargs.get('status', '')
|
||||
@ -367,7 +332,6 @@ class Notify(object):
|
||||
self.wwBot(app, status, msg)
|
||||
self.iGot(app, status, msg)
|
||||
self.pushPlus(app, status, msg)
|
||||
self.cqhttp(app, status, msg)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
100
ql_api.py
100
ql_api.py
@ -1,100 +0,0 @@
|
||||
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