-
Notifications
You must be signed in to change notification settings - Fork 0
/
regweb.py
84 lines (72 loc) · 2.91 KB
/
regweb.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 requests, datetime
from bs4 import BeautifulSoup
class regweb():
def __init__(self, username, password, server, debug=False):
self.punchUrl = server + "/action-punch-add-worktime.asp?cardnum=%s&pdate=%s&seluser=%s&ptime=%s&pdir=%s&pcom=0&sb-fix-save=Tallenna"
self.debugPunchUrl = server + "/fixpunch.asp?curdate=%s&ptype=0"
self.frontUrl = server+"/login.asp"
self.loginUrl = server+"/action-login.asp"
self.username = username
self.password = password
self.url = ""
self.debug = debug
self.cardnum = ""
self.seluser = ""
self.pdate = ""
self.ptime = ""
self.balance = ""
self.daybalance = ""
self.direction = {
'out': 0,
'in': 128
}
self.session = requests.Session()
self.cookies = {}
def getCookie(self):
self.url = self.frontUrl
try:
self.session.get(self.url)
self.cookies = self.session.cookies.get_dict()
except:
print("Could not reach login page")
exit(0)
def login(self):
self.url = self.loginUrl
data = {'username': self.username, 'password': self.password}
r = requests.post(self.url, data=data, cookies=self.cookies)
if r.status_code == 200:
soup = BeautifulSoup(r.text, 'html.parser')
soup_user = soup.find_all("div", "user")[0].find_all("p")[0]
self.seluser = soup_user.find_all("span")[1].string.strip()
self.cardnum = soup_user.find_all("span")[2].string.strip()
self.balance = soup.find_all("div", "tbpp-balances")[0].find_all("td")[1].string.strip()
else:
print("Could not login")
exit(0)
def generatePunchUrl(self):
if self.debug:
self.url = self.debugPunchUrl % (self.pdate)
else:
self.url = self.punchUrl % (self.cardnum, self.pdate, self.seluser, self.ptime, self.pdir)
def punch(self, direction, time=False, date=False):
self.pdir = self.direction[direction]
if time:
self.ptime = time
else:
self.ptime = datetime.datetime.now().strftime("%H:%M")
if date:
self.pdate = date
else:
self.pdate = datetime.datetime.now().strftime("%-d.%m.%Y")
self.generatePunchUrl()
r = requests.get(self.url, cookies=self.cookies)
if r.status_code == 200:
try:
soup = BeautifulSoup(r.text, 'html.parser')
self.dailybalance = soup.find_all("div", "stamps-heading")[0].find_all("p")[1].find_all("span")[0].string.strip()
print("This day you worked " + self.dailybalance + "h")
except:
pass
oldbalance = self.balance
self.login()
print("Balance: " + oldbalance + "h -> " + self.balance + "h")