-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreebok.py
executable file
·84 lines (65 loc) · 2.36 KB
/
reebok.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
#!/usr/bin/env python3
import http.client, urllib
import re
import sys
import time
def sendMessage(token, user, message):
conn = http.client.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({
"token": token,
"user": user,
"message": message,
}), { "Content-type": "application/x-www-form-urlencoded" })
response = conn.getresponse()
print(response.status, response.reason)
data = response.read()
print(len(data))
print(data)
def getToken(file):
tokenFile = open(file)
token = tokenFile.read()
return token.strip()
def main():
user_token = getToken(".user-key")
app_token = getToken(".app-key")
site_cookie = getToken(".site-cookie")
print("tokens: ", user_token, app_token, site_cookie)
date = "2015-07-27"
# state:
# -4: start
# -3: error
# -2: empty
# -1: no 50 years
# 0+: count in 50 years
state = -4
while (True):
conn = http.client.HTTPConnection("www.reebokinparks.com")
conn.request("GET", "/workouts/register/?date=" + date, headers = { "Cookie" : site_cookie });
response = conn.getresponse()
print("Reebok: ", response.status, response.reason)
sleepTime = 600
newState = -1
if response.status == 200:
data = response.read().decode('utf-8')
print("len of data: ", len(data))
newState = -1
searchFilled = "<p>Свободных мест на этот день больше нет!</p>"
sFilled = re.search(searchFilled, data)
if sFilled:
newState = -2
searchEmpty = "<strong>50-летия Октября</strong>,\n.*\n.*осталось мест — <strong>([0-9]*)</strong>"
sEmpty = re.search(searchEmpty, data)
if sEmpty:
newState = int(sEmpty.group(1))
if newState != state:
sleepTime = 60
print("state: ", state, " --> ", newState)
if (state != newState and newState > 0) or state == -4:
sendMessage(app_token, user_token, "Check reebok! " + str(newState) + " in 50 years")
state = newState
else:
state = -3
time.sleep(sleepTime)
if __name__ == "__main__":
sys.exit(main())