适配青龙面板
This commit is contained in:
parent
4704d8c908
commit
902785d94a
35
index.py
35
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:
|
||||||
@ -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
|
||||||
@ -228,7 +233,25 @@ class Sign(Base):
|
|||||||
return CONFIG.MESSGAE_TEMPLATE
|
return CONFIG.MESSGAE_TEMPLATE
|
||||||
|
|
||||||
|
|
||||||
def main_handler(event, context):
|
# 获取要执行兑换的cookie
|
||||||
|
pattern_pin = re.compile(r'pt_pin=([\w\W]*?);')
|
||||||
|
|
||||||
|
|
||||||
|
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"))
|
||||||
|
print('共配置{}条CK,已载入用户[{}]'.format(len(ck_list)))
|
||||||
|
if len(ck_list == 0):
|
||||||
|
print('共配置{}条CK,请添加环境变量,或查看环境变量状态'.format(len(ck_list)))
|
||||||
|
return "".join(ck_list)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# def main_handler(event, context):
|
||||||
log.info('任务开始')
|
log.info('任务开始')
|
||||||
notify = Notify()
|
notify = Notify()
|
||||||
msg_list = []
|
msg_list = []
|
||||||
@ -237,7 +260,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']
|
||||||
|
|||||||
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