-
Notifications
You must be signed in to change notification settings - Fork 0
/
genshin-os.py
82 lines (74 loc) · 3.36 KB
/
genshin-os.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
from settings import log, CONFIG
from sign import Sign
from notify import Notify
### Uncomment these two lines when running on local and run following cmd to install dotenv:
### virtualenv env
### source env/bin/activate
### pip install -r requirements.txt
### pip install python-dotenv
### python3 genshin-os.py
### deactivate
# from dotenv import load_dotenv
# load_dotenv()
import random
import time
randomSleep = random.randint(3,10)
print("Sleeping for: %ds" % randomSleep)
time.sleep(randomSleep+0.12)
if __name__ == '__main__':
notify = Notify()
msg_list = []
ret = success_num = fail_num = 0
"""
HoYoLAB Community's COOKIE
:param OS_COOKIE: HoYoLAB cookie(s) for one or more accounts.
Separate cookies for multiple accounts with the hash symbol #
e.g. cookie1text#cookie2text
Do not surround cookies with quotes "" if using Github Secrets.
"""
# Github Actions -> Settings -> Secrets
# Ensure that the Name is exactly: OS_COOKIE
# Value should look like: login_ticket=xxx; account_id=696969; cookie_token=xxxxx; ltoken=xxxx; ltuid=696969; mi18nLang=en-us; _MHYUUID=xxx
# Separate cookies for multiple accounts with the hash symbol #
# e.g. cookie1text#cookie2text
OS_COOKIE = ''
token = ''
if os.environ.get('OS_COOKIE', '') != '':
OS_COOKIE = os.environ.get('OS_COOKIE')
else:
log.error("'OS_COOKIE' not found, ensure that variable exists")
raise Exception("OS_COOKIE not found, ensure that it exists and set exactly to OS_COOKIE")
cookie_list = OS_COOKIE.split('#')
log.info(f'Number of account cookies read: {len(cookie_list)}')
for i in range(len(cookie_list)):
log.info(f'Preparing NO.{i + 1} Account Check-In...')
try:
token = cookie_list[i].split('cookie_token=')[1].split(';')[0]
msg = f' {Sign(cookie_list[i]).run()}'
msg_list.append(msg)
success_num = success_num + 1
except IndexError:
cookie_values = ["account_id","ltoken","ltuid","mi18nLang","_MHYUUID"]
for j in cookie_values:
if j not in cookie_list[i]:
log.error(f'{j} not found')
fail_num = fail_num + 1
ret = -1
log.info(f"\n\nTry these troubleshooting steps and grab the cookie again:\n -Log out and log back in\n -Ensure you are on the Daily Rewards page and not the HoyoLab Forums page\n -Try incognito mode\n -Try clearing your browser history/cache\n -Try using another browser\n")
except Exception as e:
if (len(cookie_list)>1):
log.error("If you are using multiple accounts, refer to the screenshot here https://i.imgur.com/kYRZlF1.png")
if not token:
log.error("Cookie token not found, please try to relog on the check-in page.")
msg = f' NO.{i + 1} Account:\n {e}'
msg_list.append(msg)
fail_num = fail_num + 1
log.error(msg)
ret = -1
notify.send(status=f'' if fail_num == 0 else f'Fail: {fail_num}', msg=msg_list)
if ret != 0:
log.error('program terminated with errors')
exit(ret)
log.info('exit success')
log.info("You can safely ignore the message below if the sign in is successful 'SCRIPT TERMINATED: Script haulted due to an error from the python_code module.'")