-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDartslive-Auto-Get-Bonus.py
115 lines (103 loc) · 3.92 KB
/
Dartslive-Auto-Get-Bonus.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
108
109
110
111
112
113
114
115
import requests
import time
import random
import datetime
from bs4 import BeautifulSoup
import json
import os
class Dartslive(object):
def __init__(self, email, password):
self._url_password_input = "https://card.dartslive.com/entry/login/password_input.jsp"
self._url_do_login = "https://card.dartslive.com/entry/login/doLogin.jsp"
self._url_get_bonus = "https://card.dartslive.com/account/bonus/index.jsp"
self._url_coinstore = "https://card.dartslive.com/t/coinstore/pickup.jsp"
self._url_logout = "https://card.dartslive.com/t/logout.jsp"
self._email = email
self._password = password
self._session = requests.Session()
self._text = ""
def post(self, url, data={}):
try:
response = self._session.post(url, data=data)
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
return False
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
return False
else:
time.sleep(random.randint(2, 5))
self._text = response.text
return True
def login(self):
if self.post(self._url_password_input, {'id': self._email}):
print('\tInput Email Success!')
if self.post(self._url_do_login, {
'id': self._email,
'ps': self._password
}):
soup = BeautifulSoup(self._text, "html.parser")
if soup and soup.find(id='cardtop'):
print('\tLogin Success!')
return True
print('\tLogin Error')
return False
else:
print('\tInput Email Error')
return False
def get_bonus(self):
if self.post(self._url_get_bonus):
soup = BeautifulSoup(self._text, "html.parser")
if soup and soup.find(id='coinBonus'):
print('\tGet Bonus Success!')
else:
print('\tYou have already gotten bonus before!')
return True
else:
print('\tGet Bonus Error')
return False
def show_own_coin(self):
if self.post(self._url_coinstore):
soup = BeautifulSoup(self._text, "html.parser")
total_coin = ''
this_month_coin = ''
for div in soup.findAll("div", {"class": "coinNumArea"}):
for span in div.findAll("span", {"class": "num"}):
total_coin = span.get_text()
for span in div.findAll("span", {"class": "thisMonth"}):
this_month_coin = span.get_text()
if total_coin and this_month_coin:
print('\tYou have', total_coin, this_month_coin, 'coins.')
return True
print('\tShow Coin Error')
return False
def logout(self):
if self.post(self._url_logout):
print('\tLogout Success!')
return True
else:
print('\tLogout Error')
return False
def main():
email = []
password = []
dir_path = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(dir_path, 'user.json')) as json_file:
data = json.load(json_file)
for ptt in data:
email.append(ptt['email'])
password.append(ptt['password'])
print('====================BEGIN====================')
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
for i in range(len(email)):
print('Email: ', email[i])
dartslive = Dartslive(email[i], password[i])
if dartslive.login():
if dartslive.get_bonus():
dartslive.show_own_coin()
dartslive.logout()
time.sleep(random.randint(1, 10) * 60)
print('=============== END ===============')
if __name__ == "__main__":
main()