Last active
December 15, 2015 10:19
-
-
Save sarguido/5245278 to your computer and use it in GitHub Desktop.
This is a program I wrote (for a friend...) to determine if the Lollapalooza secret sale for the cheap tickets had begun. The program uses BeautifulSoup to scrape the site, checking to see if the ticket text had been changed from "SOON." If so, it would send an alert email. The program was successful and did alert my friend when the tickets went…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2, time, smtplib, string | |
from bs4 import BeautifulSoup | |
# In this section, set up your information. TO - email address to send to. | |
# FROM - email to send from. username/password are for FROM email. | |
TO = '' | |
FROM = '' | |
username = '' | |
password = '' | |
x = 'hello' | |
while x != 'done': | |
try: | |
page = urllib2.urlopen("http://www.lollapalooza.com/tickets/").read() | |
soup = BeautifulSoup(page) | |
ticket_box = soup.find(id="ticket-box") | |
tickets = ticket_box.find_all("span") | |
ticks = tickets[0] | |
souvenir = ticks.find_all("span") | |
if souvenir[0].text == "Souvenir" and souvenir[4].text == "SOON": | |
print "Checked." | |
time.sleep(60) | |
elif souvenir[0].text == "Souvenir" and souvenir[4].text != "SOON": | |
SUBJECT = "LOLLAPALOOZA TICKETS" | |
text = "RIGHT NOW" | |
BODY = string.join(( | |
"From: %s" % FROM, | |
"To: %s" % TO, | |
"Subject: %s" % SUBJECT , | |
"", | |
text | |
), "\r\n") | |
server = smtplib.SMTP("smtp.gmail.com:587") | |
server.ehlo() | |
server.starttls() | |
server.login(username, password) | |
server.sendmail(FROM, [TO], BODY) | |
server.quit() | |
x = 'done' | |
except: | |
print "Too many requests." | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment