-
Notifications
You must be signed in to change notification settings - Fork 2
/
exchange_bot.py
96 lines (89 loc) · 3.62 KB
/
exchange_bot.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
87
88
89
90
91
92
93
94
95
96
import requests, bs4, time
from fake_useragent import UserAgent
TICKET_TYPES = [
# "day1/a", # vrijdag chill
# "day1/b", # vrijdag relax
# "day1/n", # vrijdag no camping
# "day2/a", # zaterdag chill
# "day2/b", # zaterdag relax
# "day2/n", # zaterdag no camping
# "day3/a", # zondag chill
# "day3/b", # zondag relax
# "day3/n", # zondag no camping
"combi/a", # Combi chill
"combi/b", # Combi relax
"combi/n", # Combi no camping
]
CONTACT_DETAILS = [
{
"firstname": "Firstname",
"lastname": "Lastname",
"email": "[email protected]",
"confirm": 1,
}
]
# Notify url to get notified when a ticket is found
# see https://docs.ntfy.sh/ for more info
NTFY_URL = False
REFRESH_TIMEOUT = 2
FORM_SUBMIT_TIMEOUT = 0.5
# gets the form data before submitting it,
# makes requests look more legit, probably not needed since no csrf token is used
GET_BEFORE_POST = True
FORM_GET_TIMEOUT = 0.2
chrome = UserAgent().chrome
session = requests.Session()
headers = {
"User-Agent": chrome,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
"Host": "tickets.pukkelpop.be",
"Referer": "https://tickets.pukkelpop.be/nl/meetup/demand/combi/",
"Upgrade-Insecure-Requests": "1",
"Connection": "keep-alive",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Brave";v="115", "Chromium";v="115"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
}
links_used = []
while True:
time.sleep(REFRESH_TIMEOUT)
for ticket_type in TICKET_TYPES:
try:
resp = session.get(f"https://tickets.pukkelpop.be/nl/meetup/demand/{ticket_type}/", headers=headers)
resp.raise_for_status()
main_soup = bs4.BeautifulSoup(resp.text, "html.parser")
links = main_soup.findAll("a", {"class": "button -full -arrow -sp"})
for link in main_soup.findAll("a", {"class": "button -full -arrow -sp"}):
if not link.get("href") in links_used:
# add time to print
print("Found new link: " + link.get("href"))
if NTFY_URL:
session.post(NTFY_URL, data=f"Found new pukkelpop Ticket {ticket_type}", headers={
"Title": "Pkp Ticket Found",
"Click": link.get("href")
})
form_url = link.get("href")
post_headers = {
"Referer": form_url,
"Content-Type": "application/x-www-form-urlencoded",
**headers,
}
for contact_detail in CONTACT_DETAILS:
if GET_BEFORE_POST:
time.sleep(FORM_GET_TIMEOUT)
print("Trying to get form for ticket")
session.get(form_url, headers=headers)
time.sleep(FORM_SUBMIT_TIMEOUT)
print("Trying to send form for " + contact_detail["email"])
resp = session.post(form_url, headers=post_headers, data=contact_detail)
print(resp.status_code)
links_used.append(link.get("href"))
except Exception as ex:
print(ex)