commit
b9488f5c7a
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@ -35,9 +35,13 @@ jobs:
|
||||
with:
|
||||
python-version: 3.8
|
||||
|
||||
- name: Random sleep
|
||||
if: github.event_name == 'schedule'
|
||||
run: sleep $(shuf -i 10-300 -n 1)
|
||||
|
||||
- name: Run sign
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
echo "${{ secrets.COOKIE }}" | tr '#' "\n" | sed 's/$/&#${{ secrets.SCKEY }}/g' | xargs -I {} sh -c 'echo "{}" | python3 ./genshin.py'
|
||||
echo '${{ secrets.COOKIE }}' | tr '#' '\n' | sed 's/^/-c &/g' | sed 's/$/&${{ secrets.SCKEY }}/g' | xargs -I {} sh -c 'echo "{}" | python3 ./genshin.py'
|
||||
|
||||
|
||||
20
README.md
20
README.md
@ -33,7 +33,7 @@ Genshin Impact Helper 可以自动化为你获取原神每日福利。
|
||||
|
||||
- [x] **自动签到** 程序会在每天早上自动执行签到流程,也可以随时通过部署教程的`步骤4`手动触发,具体时间参照[此处](.github/workflows/main.yml)
|
||||
- [x] **支持订阅** 通过配置`SCKEY`开启订阅,每天将签到结果推送到微信上
|
||||
- [x] **支持多账号** 不同账号的`Cookie`之间用`#`分隔,如:`yourCookie1#yourCookie2`
|
||||
- [x] **支持多账号** 不同账号的`Cookie`之间用`#`分隔,如:`myCookie1#myCookie2`
|
||||
- [x] **支持多角色** 支持绑定官服和B站渠道服角色的米游社账号
|
||||
|
||||
## 📐部署
|
||||
@ -46,7 +46,11 @@ Genshin Impact Helper 可以自动化为你获取原神每日福利。
|
||||
- 项目地址:[github/genshin-impact-helper](https://github.com/y1ndan/genshin-impact-helper)
|
||||
- 点击右上角`Fork`到自己的账号下
|
||||
|
||||
> 
|
||||

|
||||
|
||||
- 打开`Fork`后的仓库,将仓库默认分支设置为 master 分支
|
||||
|
||||

|
||||
|
||||
### 2. 获取 Cookie
|
||||
|
||||
@ -57,7 +61,9 @@ Genshin Impact Helper 可以自动化为你获取原神每日福利。
|
||||
- 按`F12`,打开`开发者工具`,找到`Network`并点击
|
||||
- 按`F5`刷新页面,按下图复制`Cookie`
|
||||
|
||||
> 
|
||||

|
||||
|
||||
- 当触发`Debugger`时,可尝试按`Ctrl + F8`关闭,然后再次刷新页面,最后复制`Cookie`
|
||||
|
||||
#### 2.2 方法二
|
||||
|
||||
@ -82,7 +88,7 @@ if (ask == true) {
|
||||
|
||||
- 回到项目页面,依次点击`Settings`-->`Secrets`-->`New secret`
|
||||
|
||||
> 
|
||||

|
||||
|
||||
- 建立名为`COOKIE`的 secret,值为`步骤2`中复制的`Cookie`内容,最后点击`Add secret`
|
||||
|
||||
@ -90,7 +96,7 @@ if (ask == true) {
|
||||
- secret名字必须为`COOKIE`!
|
||||
- secret名字必须为`COOKIE`!
|
||||
|
||||
> 
|
||||

|
||||
|
||||
### 4. 启用 Actions
|
||||
|
||||
@ -98,7 +104,7 @@ if (ask == true) {
|
||||
|
||||
返回项目主页面,点击上方的`Actions`,再点击左侧的`Genshin Impact Helper`,再点击`Run workflow`
|
||||
|
||||
> 
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
@ -149,7 +155,7 @@ Error: Process completed with exit code 255.
|
||||
- 使用 GitHub 登录 [sc.ftqq.com](http://sc.ftqq.com/?c=github&a=login) 创建账号
|
||||
- 点击「[发送消息](http://sc.ftqq.com/?c=code)」,获取`SCKEY`
|
||||
- 点击「[微信推送](http://sc.ftqq.com/?c=wechat&a=bind)」,完成微信绑定
|
||||
- 建立名为`SCKEY`的 secret,并添加获取的 SCKEY 值,开启订阅推送
|
||||
- 建立名为`SCKEY`的 secret,并添加获取的 SCKEY 值,即可开启订阅推送。注意必须加上`-s`,例子:`-s <SCKEY>`
|
||||
|
||||
## ❗️协议
|
||||
|
||||
|
||||
65
genshin.py
65
genshin.py
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import argparse
|
||||
import json
|
||||
import uuid
|
||||
import logging
|
||||
@ -114,6 +115,7 @@ class Roles(object):
|
||||
|
||||
try:
|
||||
jdict
|
||||
logging.info('账号信息获取完毕')
|
||||
except AttributeError:
|
||||
raise Exception(errstr)
|
||||
|
||||
@ -163,9 +165,7 @@ class Sign(object):
|
||||
try:
|
||||
rolesList = roles['data']['list']
|
||||
except Exception as e:
|
||||
message = roles['message']
|
||||
notify(sckey, '失败', message)
|
||||
exit(-1)
|
||||
notify(sckey, '失败', roles['message'])
|
||||
else:
|
||||
logging.info('当前账号绑定了 {} 个角色'.format(len(rolesList)))
|
||||
infoList = []
|
||||
@ -182,6 +182,7 @@ class Sign(object):
|
||||
try:
|
||||
infoList.append(json.loads(requests.Session().get(
|
||||
info_url, headers = self.get_header()).text))
|
||||
logging.info('签到信息获取完毕')
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
@ -191,21 +192,23 @@ class Sign(object):
|
||||
logging.info('任务开始')
|
||||
messageList = []
|
||||
infoList = self.get_info()
|
||||
status = '失败'
|
||||
for i in range(len(infoList)):
|
||||
if infoList[i]['data']['is_sign'] is True:
|
||||
#if infoList[i]['data']['is_sign'] is False:
|
||||
message = '旅行者 {} 号,你已经签到过了'.format(i + 1)
|
||||
notify(sckey, '成功', message)
|
||||
elif infoList[i]['data']['first_bind'] is True:
|
||||
message = '旅行者 {} 号,请先前往米游社绑定账号'.format(i + 1)
|
||||
notify(sckey, '失败', message)
|
||||
exit(-1)
|
||||
else:
|
||||
today = infoList[i]['data']['today']
|
||||
totalSignDay = infoList[i]['data']['total_sign_day']
|
||||
award = Roles(self._cookie).get_awards()['data']['awards'][totalSignDay - 1]
|
||||
awards = Roles(self._cookie).get_awards()['data']['awards']
|
||||
uid = str(self._uidList[i]).replace(
|
||||
str(self._uidList[i])[3:6], '***', 1)
|
||||
if infoList[i]['data']['is_sign'] is True:
|
||||
#if infoList[i]['data']['is_sign'] is False:
|
||||
status = '成功'
|
||||
messageList.append(self.message().format(today,
|
||||
self._regionNameList[i], uid,
|
||||
awards[totalSignDay - 1]['name'], awards[totalSignDay - 1]['cnt'],
|
||||
totalSignDay, '旅行者 {} 号,你已经签到过了'.format(i + 1), ''))
|
||||
elif infoList[i]['data']['first_bind'] is True:
|
||||
messageList.append(' 旅行者 {} 号为首次绑定,请先前往米游社App手动签到一次'.format(i + 1))
|
||||
else:
|
||||
data = {
|
||||
'act_id': Conf.act_id,
|
||||
'region': self._regionList[i],
|
||||
@ -213,11 +216,12 @@ class Sign(object):
|
||||
}
|
||||
|
||||
logging.info('准备为旅行者 {} 号签到...' \
|
||||
'\nRegion: {}\nUID: {}'.format(i + 1, self._regionNameList[i], uid))
|
||||
'\n区服: {}\nUID: {}'.format(i + 1, self._regionNameList[i], uid))
|
||||
try:
|
||||
jdict = json.loads(requests.Session().post(
|
||||
Conf.sign_url, headers = self.get_header(),
|
||||
data = json.dumps(data, ensure_ascii=False)).text)
|
||||
logging.info('签到完毕')
|
||||
except Exception as e:
|
||||
raise
|
||||
else:
|
||||
@ -226,12 +230,13 @@ class Sign(object):
|
||||
# -5003: already signed in
|
||||
if code == 0:
|
||||
status = '成功'
|
||||
|
||||
messageList.append(self.message().format(today,
|
||||
self._regionNameList[i], uid, award['name'], award['cnt'],
|
||||
totalSignDay, jdict['message'], ''))
|
||||
self._regionNameList[i], uid,
|
||||
awards[totalSignDay]['name'], awards[totalSignDay]['cnt'],
|
||||
totalSignDay + 1, jdict['message'], ''))
|
||||
else:
|
||||
status = '失败'
|
||||
messageList = jdict
|
||||
messageList.append(jdict)
|
||||
|
||||
return notify(sckey, status, messageList)
|
||||
|
||||
@ -247,6 +252,7 @@ class Sign(object):
|
||||
|
||||
|
||||
def notify(sckey, status, message):
|
||||
logging.info('签到{}: {}'.format(status, message))
|
||||
if sckey.startswith('SC'):
|
||||
logging.info('准备推送通知...')
|
||||
url = 'https://sc.ftqq.com/{}.send'.format(sckey)
|
||||
@ -264,22 +270,19 @@ def notify(sckey, status, message):
|
||||
else:
|
||||
logging.error('{}: {}'.format('推送失败', jdict))
|
||||
else:
|
||||
logging.info('未配置SCKEY,正在跳过推送')
|
||||
logging.info('未配置 SCKEY,正在跳过通知推送')
|
||||
|
||||
logging.info('签到{}: {}'.format(status, message))
|
||||
return logging.info('任务结束')
|
||||
logging.info('任务结束')
|
||||
if status == '失败':
|
||||
return exit(-1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
secret = input().strip().split('#')
|
||||
secret.append('')
|
||||
cookie = secret[0]
|
||||
sckey = secret[1]
|
||||
seconds = random.randint(10, 300)
|
||||
#seconds = random.randint(1, 3)
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', '--cookie', required=True, type=str, default='')
|
||||
parser.add_argument('-s', '--sckey', type=str, default='')
|
||||
args = parser.parse_args()
|
||||
sckey = args.sckey
|
||||
|
||||
logging.info('将在 {} 秒后开始任务...'.format(seconds))
|
||||
time.sleep(seconds)
|
||||
|
||||
Sign(cookie).run()
|
||||
Sign(args.cookie).run()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user