EpiCea/main.py

177 lines
5.5 KiB
Python

"""
-------------v1.0.0-------------
_____ _ ____
| ____|_ __ (_)/ ___|___ __ _
| _| | '_ \| | | / _ \/ _` |
| |___| |_) | | |__| __/ (_| |
|_____| .__/|_|\____\___|\__,_|
|_|
------------spekulaas-----------
"""
import json
import time
import requests
import os
from dotenv import load_dotenv
import smtplib
from email.mime.text import MIMEText
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
HOST = "https://www.ticketswap.nl"
class TicketSwap:
def __init__(self):
self.receive_mail = ""
self.main_driver = webdriver.Chrome()
self.login()
self.has_tickets = False
def login(self):
self.receive_mail = input('Notifications email: ')
username = input('Ticketswap email: ')
self.main_driver.get(HOST)
# wait for lang buttons
time.sleep(1)
try:
lang_button = self.main_driver.find_element(By.CLASS_NAME, 'e1wv5usg4')
lang_button.click()
print("done")
except:
pass
time.sleep(1)
try:
login_button = self.main_driver.find_element(By.CLASS_NAME, 'e1k05qur1').find_elements(By.TAG_NAME, 'li')[2]
login_button.click()
# await animation
time.sleep(1)
emailInput = self.main_driver.find_element(By.ID, 'email')
emailInput.send_keys(username)
emailInput.send_keys(Keys.ENTER)
email_code = input('Provide code from ticketswap in mailbox: ')
keys = self.main_driver.find_element(By.ID, 'one-time-code-input-1')
keys.send_keys(email_code)
keys.send_keys(Keys.ENTER)
except:
print("button not found")
exit(1)
time.sleep(2)
self.cookies = self.__handle_cookies(self.main_driver.get_cookies())
if 'token' not in self.cookies:
print('username or password is invalid!')
self.login()
def __handle_cookies(self, cookieList):
cookies = {}
for cookie in cookieList:
cookies[cookie['name']] = cookie['value']
return cookies
def start(self):
eventurl = input('Type here the event url: ')
while self.has_tickets is False:
print('Checking for tickets')
data = self.get_ticket(eventurl)
if data is not False:
if self.reserve_ticket(data):
self.has_tickets = True
self.main_driver.get(HOST + '/cart')
# wait till reserve time is finished
current_time = time.strftime("%H:%M:%S", time.localtime())
print(f"Reserved tickets at: {current_time}, Waiting 10 minutes, close if you got tickets")
self.send_email(self.receive_mail)
time.sleep(600)
if input("Got the tickets(Y for yes N for no)").upper() != "Y":
print("FFS be faster next time, u wasted 10 min jerking off, now someone lese got the ticket... starting again...")
self.has_tickets = False
else:
print("congratz!")
self.main_driver.quit()
exit()
def get_ticket(self, eventurl):
""" Get Cheapest ticket """
# get html from request
response = requests.get(eventurl)
html = response.content.decode("utf-8")
parsed_html = BeautifulSoup(html, "html.parser")
# check if the 'no tickets' element is present
not_exist = parsed_html.body.find('span', attrs={'class': "css-y9qk84 e1asqgj37"})
if not_exist is not None:
print("no tickets")
return False
# check if there are any listings
urlobject = parsed_html.body.findAll('a', attrs={'data-testid': 'listing'})
if urlobject is None:
print("no offers")
return False
for item in urlobject:
attributes = item.attrs
ticket_link = attributes['href']
print("got offer")
return ticket_link
print('Possible that you have the wrong event url')
return False
def reserve_ticket(self, content):
""" Reserve ticket """
self.main_driver.get(content)
try:
reserve_button = self.main_driver.find_element(By.CLASS_NAME, 'css-17jso0u')
reserve_button.click()
except:
print(":( they got sniped in front of you, trying again")
time.sleep(5)
return False
print("RESERVED TICKKEttt!!!")
time.sleep(3)
return True
def send_email(self,recipient):
subject = "Email Subject"
body = "Je kan je kaartjes kopen man! je kan uit checken via je telefoon app!!!"
sender = os.getenv('HOST_EMAIL')
password = os.getenv('HOST_PASS')
msg = MIMEText(body)
msg['Subject'] = "JE HEBT TICKETS!!"
msg['From'] = sender
msg['To'] = recipient
smtp_server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtp_server.login(sender, password)
smtp_server.sendmail(sender, recipient, msg.as_string())
smtp_server.quit()
if __name__ == "__main__":
load_dotenv()
t = TicketSwap()
t.start()