-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.py
107 lines (94 loc) · 3.56 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import re
import time
import requests
import json
with open(os.getcwd() + "/config.json", "r", encoding="utf-8") as f:
config = json.load(f)
def _autosign(sess):
signinfo = sess.post(
'https://www.gamer.com.tw/ajax/signin.php', data={'action': '2'}).json()
if signinfo['data']['signin'] == 1:
return
token = sess.get(
'https://www.gamer.com.tw/ajax/get_csrf_token.php').text
jsoninfo = sess.post(
'https://www.gamer.com.tw/ajax/signin.php', data={'action': '1', 'token': token})
jsoninfo = jsoninfo.json()
if 'data' in jsoninfo:
print(f'巴哈姆特自動簽到成功!!\n已簽到第 {str(jsoninfo["data"]["days"])} 天')
else:
print('簽到失敗')
sess.cookies.set('ckBahamutCsrfToken',
token[:16], domain='.gamer.com.tw', secure=True)
sess.post('https://api.gamer.com.tw/mobile_app/bahamut/v1/sign_in_ad_start.php',
headers={'X-Bahamut-Csrf-Token': token[:16]})
time.sleep(30)
sess.post('https://api.gamer.com.tw/mobile_app/bahamut/v1/sign_in_ad_finished.php',
headers={'X-Bahamut-Csrf-Token': token[:16]})
def _autoanswer(sess):
snweb = sess.get(
'https://api.gamer.com.tw/mobile_app/bahamut/v1/home.php?owner=blackXblue&page=1')
sn = snweb.json()['creation'][0]['sn']
answeb = sess.get(
'https://api.gamer.com.tw/mobile_app/bahamut/v1/home_creation_detail.php?sn=' + str(sn))
ans = re.findall(r"A:(\d)<", answeb.json()['content'])[0]
tokenweb = sess.get(
'https://ani.gamer.com.tw/ajax/animeGetQuestion.php?t=' + str(int(time.time() * 1000)))
token = tokenweb.json().get('token')
if token is None:
print('Missing token. Body: {}'.format(tokenweb.json()))
return
data = {
'token': token,
'ans': ans,
't': str(int(time.time() * 1000))
}
c = sess.post(
'https://ani.gamer.com.tw/ajax/animeAnsQuestion.php', data=data)
jsoninfo = c.json()
if jsoninfo['ok'] == 1:
print(jsoninfo['gift'])
else:
print('答案錯誤')
def _guildsign(sess):
guildtext = sess.get(
'https://api.gamer.com.tw/ajax/common/topBar.php?type=forum').text
for _sn in re.findall(r'guild\.php\?gsn=(\d*)', guildtext):
jsoninfo = sess.post(
'https://guild.gamer.com.tw/ajax/guildSign.php', data={'sn': _sn}).json()
print(jsoninfo['msg'])
def _login(data):
sess = requests.session()
sess.headers.update(
{
'user-agent': 'Bahadroid (https://www.gamer.com.tw/)',
'x-bahamut-app-instanceid': 'cc2zQIfDpg4',
'x-bahamut-app-android': 'tw.com.gamer.android.activecenter',
'x-bahamut-app-version': '251',
'content-type': 'application/x-www-form-urlencoded',
'content-length': '44',
'accept-encoding': 'gzip',
'cookie': 'ckAPP_VCODE=7045'
},
)
account = sess.post(
'https://api.gamer.com.tw/mobile_app/user/v3/do_login.php', data=data)
account_f = account.json()
sess.headers = {
'user-agent': 'Bahadroid (https://www.gamer.com.tw/)',
'x-bahamut-app-instanceid': 'cc2zQIfDpg4',
'x-bahamut-app-android': 'tw.com.gamer.android.activecenter',
'x-bahamut-app-version': '251',
'accept-encoding': 'gzip'
}
_autosign(sess)
_autoanswer(sess)
_guildsign(sess)
if __name__ == "__main__":
data = {
'uid': config['account']['username'],
'passwd': config['account']['password'],
'vcode': '7045'
}
_login(data)