-
-
Save windreamer/5803695 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
#! /usr/bin/python | |
import urllib2 | |
import os | |
from BeautifulSoup import BeautifulSoup | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
def check_tickets(url): | |
#url = 'http://www.chncpa.org/ycgp/jmxx/2011-03-30/87483.shtml' | |
print url | |
id = get_id_by_ticket_url(url) | |
unit_url = 'http://ticket.chncpa.org/unit.jsp?productId=' + id | |
data = urllib2.urlopen(unit_url) | |
soup = BeautifulSoup(data) | |
img = soup.findAll('img') | |
if len(img)>0: | |
concert_title = get_ticket_title(url) | |
print concert_title | |
print 'tickets!!!' | |
os.system('echo %s | mutt [email protected] -s "you can buy tickets now %s "' % (url, concert_title)) | |
else: | |
print 'please wait' | |
def get_ticket_title(url): | |
concert_detail_data = urllib2.urlopen(url) | |
concert_detail_soup = BeautifulSoup(concert_detail_data) | |
concert_title = concert_detail_soup.head.title.string | |
return concert_title | |
def get_id_by_ticket_url(url): | |
tmp = url.split('/') | |
tmp = tmp[-1:][0] | |
id = tmp.split('.')[0] | |
return id | |
if __name__=='__main__': | |
file = open('tickets.txt') | |
for url in file.readlines(): | |
check_tickets(url) | |
file.close() |
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
*/60 6-23 * * * /home/jollychang/tickets/check_tickets.py |
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
http://www.chncpa.org/ycgp/jmxx/2011-11-04/261629.shtml | |
http://www.chncpa.org/ycgp/jmxx/2011-11-04/261420.shtml | |
http://www.chncpa.org/ycgp/jmxx/2011-03-01/51351.shtml | |
http://www.chncpa.org/ycgp/jmxx/2011-03-31/90641.shtml | |
http://www.chncpa.org/ycgp/jmxx/2011-11-04/261406.shtml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment