-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
86 lines (63 loc) · 2.33 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
import requests
import json
import re
import sheetspart
import datetime
import slackAnnounce
from bs4 import BeautifulSoup
def getLogin(username,password):
url = "https://www.stepcount.org.uk/login"
data = {
"lemail":username,
"lpw":password,
"submit":"Log in",
"gogoin":"yeh"
}
r = session.post(url=url, data=data)
print(session.cookies.get_dict())
def getLeaderBoard():
url = "https://www.stepcount.org.uk/my-leaderboard?mywork"
r = session.get(url)
print(r)
print(len(r.content))
content = r.content.decode('UTF-8')
leaderBoard = []
soup = BeautifulSoup(content,'html.parser')
lbl = soup.find_all(name='div',class_=re.compile("lead_bd(?![0-9])"))
for tag in lbl:
entry = BeautifulSoup(str(tag),'html.parser')
rawName = entry.find(name="span", class_="lb_name").text
if rawName[-16:] == "Unity | Game Ops":
rawName = rawName[0:-16]
rawName = re.sub(r" \([0-9]*.{2}\)","",rawName)
rawSteps = entry.find(name="div", class_="lead_bd3").text
if rawSteps[-6:] == " Steps":
rawSteps = re.sub(r"[^0-9]","",rawSteps)
int(rawSteps)
leaderBoardEntry = {"team":rawName,"steps":rawSteps}
print(leaderBoardEntry)
leaderBoard.append(leaderBoardEntry)
#lb_name
#lead_bd3
leaderBoard = {"timestamp" : datetime.datetime.now().strftime(r"%y-%m-%d %H:%M"), "rows":leaderBoard}
return leaderBoard
try:
j = json.load(open("auth.json","r"))
if "username" not in j or "password" not in j:
raise Exception("could not load username and password")
except Exception as e:
j = {"username":"", "password":""}
session = requests.Session()
def hourly():
getLogin(j["username"],j["password"])
leaderBoard = getLeaderBoard()
sheetspart.loadSheetsConfig()
sheetspart.RegularUpdate(leaderBoard)
def daily():
getLogin(j["username"],j["password"])
leaderBoard = getLeaderBoard()
sheetspart.loadSheetsConfig()
sheetspart.RegularUpdate(leaderBoard,updateRange=sheetspart.sheetsConfig["dailyRange"])
config = json.load(open("sheetsConfig.json","r"))
message = slackAnnounce.prepareMessage(config["sheetID"],config["slackRange"])
slackAnnounce.postToSlack(message)