1
1
import urllib2
2
- import simplejson
3
2
from lxml import html
4
3
from email .MIMEText import MIMEText
5
4
import smtplib
@@ -13,7 +12,7 @@ def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
13
12
msg ['From' ] = from_addr
14
13
msg ['To' ] = to_addr
15
14
msg ['Reply-To' ] = 'happyhours@noreply.com'
16
-
15
+
17
16
server = smtplib .SMTP ('smtp.gmail.com' ,587 ) #port 465 or 587
18
17
server .ehlo ()
19
18
server .starttls ()
@@ -46,37 +45,37 @@ def get_all_tags(url,tag):
46
45
'table table div table td' )
47
46
48
47
49
- # Then, I'm going to sort out the *exact* parts of the page
48
+ # Then, I'm going to sort out the *exact* parts of the page
50
49
# that match what I'm looking for...
51
50
for t in tables :
52
51
if t .cssselect ('p.calendar_EventTitle' ):
53
52
found_happy_hours .append (t .text_content ())
54
53
55
54
print "The scraper found %d happy hours!" % len (found_happy_hours )
56
-
57
- # Now I'm going to loop through the food I like
55
+
56
+ # Now I'm going to loop through the food I like
58
57
# and see if any of the happy hour descriptions match
59
58
for food in stuff_i_like :
60
59
for hh in found_happy_hours :
61
60
# checking for text AND making sure I don't have duplicates
62
- if food in hh and hh not in my_happy_hours :
61
+ if food in hh and hh not in my_happy_hours :
63
62
print "YAY! I found some %s!" % food
64
63
my_happy_hours .append (hh )
65
-
64
+
66
65
print "I think you might like %d of them, yipeeeee!" % len (my_happy_hours )
67
-
66
+
68
67
#Now, let's make a mail message we can read:
69
68
message = 'Hey Katharine,\n \n \n '
70
- message += 'OMG, I found some stuff for you in Downtown, take a look.\n \n '
69
+ message += 'OMG, I found some stuff for you in Downtown, take a look.\n \n '
71
70
message += '==============================\n ' .join (my_happy_hours )
72
- message = message .encode ('utf-8' )
71
+ message = message .encode ('utf-8' )
73
72
# To read more about encoding:
74
73
# http://diveintopython.org/xml_processing/unicode.html
75
74
message = message .replace ('\t ' ,'' ).replace ('\r ' ,'' )
76
75
message += '\n \n XOXO,\n Your Py Script'
77
76
78
77
#And email it to ourselves!
79
78
email = 'katharine@pyladies.com'
80
- send_email ('Happy Hour Update' ,message ,
79
+ send_email ('Happy Hour Update' ,message ,
81
80
from_addr = GMAIL_LOGIN , to_addr = email )
82
81
0 commit comments