-
Notifications
You must be signed in to change notification settings - Fork 0
/
padel_hustler.py
67 lines (49 loc) · 1.94 KB
/
padel_hustler.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
import requests
from dotenv import load_dotenv
import os
from urllib.parse import urlparse, parse_qs
from dateutil.parser import parse
from datetime import timedelta
import time
import pytz
# URL of event you want to sign up to
event_url = 'https://www.ntnuitennis.no/timeinfo.php?timeid=65&spilletid=20230221T15:00:00&lang=no'
# Getting credentials
load_dotenv(dotenv_path='./henrik_credentials.env')
#YOU NEED TO CHANGE THESE PARAMETERS IF YOU DO NOT STORE THEM IN A CREDENTIALS.ENV FILE
email = os.getenv('email')
password = os.getenv('password')
vikar_id = os.getenv('vikar_id')
# Logging in
s = requests.Session()
# Signing up
registration_url = event_url + f'&leggtilvikarid={vikar_id}'
event_time = parse(parse_qs(urlparse(event_url).query)['spilletid'][0])
registration_time = event_time - timedelta(hours=72)
utc_registration_time = registration_time.astimezone(pytz.UTC)
time_diff = float('inf')
while time_diff > 4: #to not kill the server too early
response = s.get(event_url)
time_diff = (utc_registration_time - parse(response.headers['Date'])).total_seconds()
print(f"Time to registration: {time_diff} seconds")
time.sleep(time_diff/2) #second
home_url = "https://www.ntnuitennis.no/index.php?lang=no"
login_values = {'email': email,
'password': password,
'lang': "no",
'rememberme': "on"}
r = s.post(url=home_url, data=login_values)
confirmation_str = "Kode for tilgang til bygget:"
response = s.get(registration_url)
while confirmation_str not in response.text:
time_diff = (utc_registration_time - parse(response.headers['Date'])).total_seconds()
if time_diff < -60:
print("Time since registration exceeds 60 sec")
break
time.sleep(0.05) #0.05 second sleep to avoid ddos
response = s.get(registration_url)
#Check if working
if confirmation_str in response.text:
print("Woop woop time to kick ass")
else:
print("Buhu dunno why but it didn't work:(")