Skip to content

Commit

Permalink
Add the search term to the subject of the email
Browse files Browse the repository at this point in the history
  • Loading branch information
umrysh committed Jan 17, 2014
1 parent fa1ee86 commit eb1f560
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions twitterSearch.py
Expand Up @@ -44,7 +44,7 @@ def __init__(self, search="softlayer", server="smtp.gmail.com",
self.logfile = logfilename or 'tweet.id'

self.date = datetime.datetime.now().strftime("%d/%m/%Y %H:%M")
self.subject = "%s twitter mentions %s " % ('%d', self.date)
self.subject = "%s %s twitter mentions %s " % ('%d','%s', self.date)
self.smtp_message = "\n".join([
"From: %s",
"To: %s",
Expand Down Expand Up @@ -72,15 +72,15 @@ def log_value(self, value):
with open(self.logfile, 'w+') as f:
f.write(str(value))

def _format_message(self, subject, body, count):
def _format_message(self, subject, body, count,search):
return self.smtp_message % (
self.from_, self.to,
subject % count,
subject % (count,search),
self.date,
body.encode('utf8')
)

def send_mail(self, message, count):
def send_mail(self, message, count,search):
try:
smtp = SMTP()
smtp.connect(self.server, self.port)
Expand All @@ -89,7 +89,7 @@ def send_mail(self, message, count):
smtp.ehlo()
smtp.login(self.user, self.passwd)
smtp.sendmail(self.from_, self.to, self._format_message(self.subject,
message, count))
message, count,search))
smtp.quit()

except Exception, exc:
Expand Down Expand Up @@ -139,4 +139,4 @@ def status_by_search(self, search):
unformatted_body, count = notifier.status_by_search(notifier.search_term)
if count > 0:
body = messages_to_string(unformatted_body)
notifier.send_mail(body, count)
notifier.send_mail(body, count,key)

0 comments on commit eb1f560

Please sign in to comment.