Merge pull request #87 from y1ndan/dev

Dev
This commit is contained in:
y1ndan 2021-01-04 18:13:29 +08:00 committed by GitHub
commit b9488f5c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 42 deletions

View File

@ -35,9 +35,13 @@ jobs:
with: with:
python-version: 3.8 python-version: 3.8
- name: Random sleep
if: github.event_name == 'schedule'
run: sleep $(shuf -i 10-300 -n 1)
- name: Run sign - name: Run sign
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -r requirements.txt 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'

View File

@ -33,7 +33,7 @@ Genshin Impact Helper 可以自动化为你获取原神每日福利。
- [x] **自动签到** 程序会在每天早上自动执行签到流程,也可以随时通过部署教程的`步骤4`手动触发,具体时间参照[此处](.github/workflows/main.yml) - [x] **自动签到** 程序会在每天早上自动执行签到流程,也可以随时通过部署教程的`步骤4`手动触发,具体时间参照[此处](.github/workflows/main.yml)
- [x] **支持订阅** 通过配置`SCKEY`开启订阅,每天将签到结果推送到微信上 - [x] **支持订阅** 通过配置`SCKEY`开启订阅,每天将签到结果推送到微信上
- [x] **支持多账号** 不同账号的`Cookie`之间用`#`分隔,如:`yourCookie1#yourCookie2` - [x] **支持多账号** 不同账号的`Cookie`之间用`#`分隔,如:`myCookie1#myCookie2`
- [x] **支持多角色** 支持绑定官服和B站渠道服角色的米游社账号 - [x] **支持多角色** 支持绑定官服和B站渠道服角色的米游社账号
## 📐部署 ## 📐部署
@ -46,7 +46,11 @@ Genshin Impact Helper 可以自动化为你获取原神每日福利。
- 项目地址:[github/genshin-impact-helper](https://github.com/y1ndan/genshin-impact-helper) - 项目地址:[github/genshin-impact-helper](https://github.com/y1ndan/genshin-impact-helper)
- 点击右上角`Fork`到自己的账号下 - 点击右上角`Fork`到自己的账号下
> ![fork](https://i.loli.net/2020/10/28/qpXowZmIWeEUyrJ.png) ![fork](https://i.loli.net/2020/10/28/qpXowZmIWeEUyrJ.png)
- 打开`Fork`后的仓库,将仓库默认分支设置为 master 分支
![default-master](https://i.loli.net/2021/01/04/eRYf8hTAvcOQnBI.jpg)
### 2. 获取 Cookie ### 2. 获取 Cookie
@ -57,7 +61,9 @@ Genshin Impact Helper 可以自动化为你获取原神每日福利。
- 按`F12`,打开`开发者工具`,找到`Network`并点击 - 按`F12`,打开`开发者工具`,找到`Network`并点击
- 按`F5`刷新页面,按下图复制`Cookie` - 按`F5`刷新页面,按下图复制`Cookie`
> ![cookie](https://i.loli.net/2020/10/28/TMKC6lsnk4w5A8i.png) ![cookie](https://i.loli.net/2020/10/28/TMKC6lsnk4w5A8i.png)
- 当触发`Debugger`时,可尝试按`Ctrl + F8`关闭,然后再次刷新页面,最后复制`Cookie`
#### 2.2 方法二 #### 2.2 方法二
@ -82,7 +88,7 @@ if (ask == true) {
- 回到项目页面,依次点击`Settings`-->`Secrets`-->`New secret` - 回到项目页面,依次点击`Settings`-->`Secrets`-->`New secret`
> ![new-secret.png](https://i.loli.net/2020/10/28/sxTuBFtRvzSgUaA.png) ![new-secret.png](https://i.loli.net/2020/10/28/sxTuBFtRvzSgUaA.png)
- 建立名为`COOKIE`的 secret值为`步骤2`中复制的`Cookie`内容,最后点击`Add secret` - 建立名为`COOKIE`的 secret值为`步骤2`中复制的`Cookie`内容,最后点击`Add secret`
@ -90,7 +96,7 @@ if (ask == true) {
- secret名字必须为`COOKIE` - secret名字必须为`COOKIE`
- secret名字必须为`COOKIE` - secret名字必须为`COOKIE`
> ![add-secret](https://i.loli.net/2020/10/28/sETkVdmrNcCUpgq.png) ![add-secret](https://i.loli.net/2020/10/28/sETkVdmrNcCUpgq.png)
### 4. 启用 Actions ### 4. 启用 Actions
@ -98,7 +104,7 @@ if (ask == true) {
返回项目主页面,点击上方的`Actions`,再点击左侧的`Genshin Impact Helper`,再点击`Run workflow` 返回项目主页面,点击上方的`Actions`,再点击左侧的`Genshin Impact Helper`,再点击`Run workflow`
> ![run](https://i.loli.net/2020/10/28/5ylvgdYf9BDMqAH.png) ![run](https://i.loli.net/2020/10/28/5ylvgdYf9BDMqAH.png)
</details> </details>
@ -149,7 +155,7 @@ Error: Process completed with exit code 255.
- 使用 GitHub 登录 [sc.ftqq.com](http://sc.ftqq.com/?c=github&a=login) 创建账号 - 使用 GitHub 登录 [sc.ftqq.com](http://sc.ftqq.com/?c=github&a=login) 创建账号
- 点击「[发送消息](http://sc.ftqq.com/?c=code)」,获取`SCKEY` - 点击「[发送消息](http://sc.ftqq.com/?c=code)」,获取`SCKEY`
- 点击「[微信推送](http://sc.ftqq.com/?c=wechat&a=bind)」,完成微信绑定 - 点击「[微信推送](http://sc.ftqq.com/?c=wechat&a=bind)」,完成微信绑定
- 建立名为`SCKEY`的 secret并添加获取的 SCKEY 值,开启订阅推送 - 建立名为`SCKEY`的 secret并添加获取的 SCKEY 值,即可开启订阅推送。注意必须加上`-s`,例子:`-s <SCKEY>`
## ❗️协议 ## ❗️协议

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import requests import requests
import argparse
import json import json
import uuid import uuid
import logging import logging
@ -114,6 +115,7 @@ class Roles(object):
try: try:
jdict jdict
logging.info('账号信息获取完毕')
except AttributeError: except AttributeError:
raise Exception(errstr) raise Exception(errstr)
@ -163,9 +165,7 @@ class Sign(object):
try: try:
rolesList = roles['data']['list'] rolesList = roles['data']['list']
except Exception as e: except Exception as e:
message = roles['message'] notify(sckey, '失败', roles['message'])
notify(sckey, '失败', message)
exit(-1)
else: else:
logging.info('当前账号绑定了 {} 个角色'.format(len(rolesList))) logging.info('当前账号绑定了 {} 个角色'.format(len(rolesList)))
infoList = [] infoList = []
@ -182,6 +182,7 @@ class Sign(object):
try: try:
infoList.append(json.loads(requests.Session().get( infoList.append(json.loads(requests.Session().get(
info_url, headers = self.get_header()).text)) info_url, headers = self.get_header()).text))
logging.info('签到信息获取完毕')
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
@ -191,21 +192,23 @@ class Sign(object):
logging.info('任务开始') logging.info('任务开始')
messageList = [] messageList = []
infoList = self.get_info() infoList = self.get_info()
status = '失败'
for i in range(len(infoList)): for i in range(len(infoList)):
today = infoList[i]['data']['today']
totalSignDay = infoList[i]['data']['total_sign_day']
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 True:
#if infoList[i]['data']['is_sign'] is False: #if infoList[i]['data']['is_sign'] is False:
message = '旅行者 {} 号,你已经签到过了'.format(i + 1) status = '成功'
notify(sckey, '成功', message) 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: elif infoList[i]['data']['first_bind'] is True:
message = '旅行者 {} 号,请先前往米游社绑定账号'.format(i + 1) messageList.append(' 旅行者 {} 号为首次绑定,请先前往米游社App手动签到一次'.format(i + 1))
notify(sckey, '失败', message)
exit(-1)
else: else:
today = infoList[i]['data']['today']
totalSignDay = infoList[i]['data']['total_sign_day']
award = Roles(self._cookie).get_awards()['data']['awards'][totalSignDay - 1]
uid = str(self._uidList[i]).replace(
str(self._uidList[i])[3:6], '***', 1)
data = { data = {
'act_id': Conf.act_id, 'act_id': Conf.act_id,
'region': self._regionList[i], 'region': self._regionList[i],
@ -213,11 +216,12 @@ class Sign(object):
} }
logging.info('准备为旅行者 {} 号签到...' \ logging.info('准备为旅行者 {} 号签到...' \
'\nRegion: {}\nUID: {}'.format(i + 1, self._regionNameList[i], uid)) '\n区服: {}\nUID: {}'.format(i + 1, self._regionNameList[i], uid))
try: try:
jdict = json.loads(requests.Session().post( jdict = json.loads(requests.Session().post(
Conf.sign_url, headers = self.get_header(), Conf.sign_url, headers = self.get_header(),
data = json.dumps(data, ensure_ascii=False)).text) data = json.dumps(data, ensure_ascii=False)).text)
logging.info('签到完毕')
except Exception as e: except Exception as e:
raise raise
else: else:
@ -226,14 +230,15 @@ class Sign(object):
# -5003: already signed in # -5003: already signed in
if code == 0: if code == 0:
status = '成功' status = '成功'
messageList.append(self.message().format(today,
self._regionNameList[i], uid, award['name'], award['cnt'],
totalSignDay, jdict['message'], ''))
else:
status = '失败'
messageList = jdict
return notify(sckey, status, messageList) messageList.append(self.message().format(today,
self._regionNameList[i], uid,
awards[totalSignDay]['name'], awards[totalSignDay]['cnt'],
totalSignDay + 1, jdict['message'], ''))
else:
messageList.append(jdict)
return notify(sckey, status, messageList)
def message(self): def message(self):
return ''' return '''
@ -247,6 +252,7 @@ class Sign(object):
def notify(sckey, status, message): def notify(sckey, status, message):
logging.info('签到{}: {}'.format(status, message))
if sckey.startswith('SC'): if sckey.startswith('SC'):
logging.info('准备推送通知...') logging.info('准备推送通知...')
url = 'https://sc.ftqq.com/{}.send'.format(sckey) url = 'https://sc.ftqq.com/{}.send'.format(sckey)
@ -264,22 +270,19 @@ def notify(sckey, status, message):
else: else:
logging.error('{}: {}'.format('推送失败', jdict)) logging.error('{}: {}'.format('推送失败', jdict))
else: else:
logging.info('未配置SCKEY,正在跳过推送') logging.info('未配置 SCKEY,正在跳过通知推送')
logging.info('签到{}: {}'.format(status, message)) logging.info('任务结束')
return logging.info('任务结束') if status == '失败':
return exit(-1)
if __name__ == '__main__': if __name__ == '__main__':
secret = input().strip().split('#') parser = argparse.ArgumentParser()
secret.append('') parser.add_argument('-c', '--cookie', required=True, type=str, default='')
cookie = secret[0] parser.add_argument('-s', '--sckey', type=str, default='')
sckey = secret[1] args = parser.parse_args()
seconds = random.randint(10, 300) sckey = args.sckey
#seconds = random.randint(1, 3)
logging.info('将在 {} 秒后开始任务...'.format(seconds)) Sign(args.cookie).run()
time.sleep(seconds)
Sign(cookie).run()