-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoulvoice.py
66 lines (53 loc) · 2.12 KB
/
soulvoice.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
import os
import logging
import requests
from bs4 import BeautifulSoup
import datetime, random, time
cookie = os.environ['soulvoice_cookie']
class soulvoice:
def login(self,cookie):
url = 'https://pt.soulvoice.club/attendance.php'
headers = {
'cookie': cookie,
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
}
# time.sleep(random.randint(10, 1000)
re = requests.get(url, headers=headers)
content = re.text
return content
def check(self,content):
soup = BeautifulSoup(content, features="html5lib")
username = soup.select('span[class="nowrap"]>a>b')[0].get_text()
tishi = soup.select('td[class="bottom"]')[0].get_text()
total = tishi.split(':')[1].split(')')[0].split('(')[0]
reward = tishi.split(':')[1].split(')')[0].split('(')[1]
logging.info(f'{username} {tishi}')
if '签到已得' in tishi:
code = 1
else:
code = 0
return username,code,total,reward
def pushplus(self, pushplus_token, content):
url = 'http://www.pushplus.plus/send'
html = content.replace("\n", "<br/>")
data = {
'token': pushplus_token,
"title": "PTtime 签到通知",
"content": html,
'template': 'json'
}
requests.post(url=url, params=data)
def main(self) :
try:
content = self.login(cookie)
username, code, total, reward = self.check(content)
if code == 1:
message = username + '您好,聆音签到成功' + '\n' + '本次签到获得' + reward + ('魔力值') + '\n''当前总魔力值' + total
else:
message = '签到失败,请手动签到并检查'
except:
message = '签到失败,脚本出错'
self.pushplus(os.environ['PUSH_PLUS_TOKEN'], message)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
soulvoice().main()