Last active
August 24, 2023 03:13
-
-
Save guohoo/b7aa2e55d18a4d4e64e852d187bdbf99 to your computer and use it in GitHub Desktop.
原神国际服每日签到 | HoYoLAB daliy check-in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import os | |
# 设置需要签到的项目(GS为原神,HSR为星穹铁道,HK3为崩坏三):True为开,False为关 | |
profiles = { | |
'GS': True, | |
'HSR': True, | |
'HK3': True | |
} | |
# 签到的api接口 | |
apiDict = { | |
'GS': 'https://sg-hk4e-api.hoyolab.com/event/sol/sign?lang=zh-tw&act_id=e202102251931481', | |
'HSR': 'https://sg-public-api.hoyolab.com/event/luna/os/sign?lang=zh-tw&act_id=e202303301540311', | |
'HK3': 'https://sg-public-api.hoyolab.com/event/mani/sign?lang=zh-tw&act_id=e202110291205111' | |
} | |
# 定义请求头 | |
reqHeader = { | |
'cookie': '', | |
'Accept': 'application/json, text/plain, */*', | |
'Accept-Encoding': 'gzip, deflate, br', | |
'Connection': 'keep-alive', | |
'x-rpc-app_version': '2.34.1', | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', | |
'x-rpc-client_type': '4', | |
'Referer': 'https://act.hoyolab.com/', | |
'Origin': 'https://act.hoyolab.com' | |
} | |
# 签到 | |
def checkIn(cookie, api): | |
reqHeader.update({'cookie': cookie}) | |
respond = requests.post(url=api, headers=reqHeader) | |
respond.encoding = 'utf-8' | |
respondDict = json.loads(respond.text) | |
return respondDict | |
# 打印签到结果 | |
def logPrint(gameTitle, respondDict): | |
retcode = respondDict.get('retcode') | |
message = respondDict.get('message') | |
if retcode == 0: | |
print(f'{gameTitle}:签到成功(~ ̄▽ ̄)~') | |
else: | |
print(f'{gameTitle}:签到失败,原因是{message}') | |
def main(): | |
cookiesList = os.environ['HOYOLAB_COOKIE'].split('|') # 从action secret获取cookie列表 | |
accountNum = len(cookiesList) | |
print(f'共检测到{accountNum}个HOYOLAB账户,开始签到') | |
for cookie in cookiesList: | |
hoyolabUid = cookie.split('ltuid=')[1].split(';')[0] # 从cookie中过滤出ltuid的值 | |
print(f'正在为{hoyolabUid}签到……') | |
for gameTitle, status in profiles.items(): | |
if status: | |
api = apiDict[gameTitle] | |
respondDict = checkIn(cookie, api) | |
logPrint(gameTitle, respondDict) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment