comparison scrape-vb.py @ 5:275603a8e2ae

Read config file from $HOME as well as CWD (use dotfile for $HOME)
author darius
date Tue, 28 Aug 2007 02:58:50 +0000
parents e3f4ef0b6e39
children 9f3eb9a07966
comparison
equal deleted inserted replaced
4:e3f4ef0b6e39 5:275603a8e2ae
4 # Screen scraper for Virgin Blue to look for happy hour deals 4 # Screen scraper for Virgin Blue to look for happy hour deals
5 # 5 #
6 # Prints out (and emails) when criteria match based on cost, 6 # Prints out (and emails) when criteria match based on cost,
7 # destination, etc 7 # destination, etc
8 # 8 #
9 # $Id: scrape-vb.py,v 1.3 2007/08/27 02:29:27 darius Exp $ 9 # $Id: scrape-vb.py,v 1.4 2007/08/28 02:58:50 darius Exp $
10 ############################################################################ 10 ############################################################################
11 # 11 #
12 # Copyright (C) 2007 Daniel O'Connor. All rights reserved. 12 # Copyright (C) 2007 Daniel O'Connor. All rights reserved.
13 # 13 #
14 # Redistribution and use in source and binary forms, with or without 14 # Redistribution and use in source and binary forms, with or without
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # SUCH DAMAGE. 33 # SUCH DAMAGE.
34 # 34 #
35 ############################################################################ 35 ############################################################################
36 36
37 import re, BeautifulSoup, datetime, time, smtplib, sys, urllib, ConfigParser 37 import os, re, BeautifulSoup, datetime, time, smtplib, sys, urllib, ConfigParser
38 38
39 parsetitle = re.compile('([a-z ]+) - ([a-z ]+) \$([0-9]+)', re.IGNORECASE) 39 parsetitle = re.compile('([a-z ]+) - ([a-z ]+) \$([0-9]+)', re.IGNORECASE)
40 parsetper = re.compile('Travel Period: ([0-9]+/[0-9]+/[0-9]+) - ([0-9]+/[0-9]+/[0-9]+)', re.IGNORECASE) 40 parsetper = re.compile('Travel Period: ([0-9]+/[0-9]+/[0-9]+) - ([0-9]+/[0-9]+/[0-9]+)', re.IGNORECASE)
41 41
42 conf = ConfigParser.ConfigParser() 42 conf = ConfigParser.ConfigParser()
43 conf.add_section('global') 43 conf.add_section('global')
44 conf.set('global', 'mailsubj', 'Virgin Blue Happy Hour Deals') 44 conf.set('global', 'mailsubj', 'Virgin Blue Happy Hour Deals')
45 conf.set('global', 'vburl', 'http://virginblue.com.au') 45 conf.set('global', 'vburl', 'http://virginblue.com.au')
46 conf.read('scrape-vb.ini') 46
47 conflist = ['scrape-vb.ini']
48 if ('HOME' in os.environ):
49 conflist.append(os.path.expanduser('~/.scrape-vb.ini'))
50 conf.read(conflist)
47 51
48 try: 52 try:
49 #f = open("vb-happyhour.html") 53 #f = open("vb-happyhour.html")
50 f = urllib.urlopen(conf.get('global', 'vburl')) 54 f = urllib.urlopen(conf.get('global', 'vburl'))
51 except IOError, e: 55 except IOError, e: