-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotifier.py
61 lines (45 loc) · 1.37 KB
/
notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
file: notifier.py
author: Christoffer Rosen <[email protected]>
date: December, 2013
description: Notification system using gmail to notify subscribers that
a repo's analysis has been completed.
"""
import smtplib
from caslogging import logging
class Notifier:
def __init__(self, gmail_user, gmail_pwd):
"""
Constructor
"""
self.gmail_user = gmail_user
self.gmail_pwd = gmail_pwd
self.subscribers = []
def addSubscribers(self, users):
"""
Subscribes a list of users to be notified next time, overriding
previous subscribers
@param users: an array containing e-mail address of future subscribers
"""
self.subscribers = users
def notify(self):
"""
Notify all subscribers that repo has been analyzed and is ready
to be viewed
"""
FROM = "[email protected]"
TO = self.subscribers
SUBJECT = "Your repository has been analyzed"
TEXT = "Your analyzed repository is now ready to be viewed at http://kiwi.se.rit.edu/"
# prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(self.gmail_user, self.gmail_pwd)
server.sendmail(FROM, TO, message)
server.quit()
logging.info("Notification sent successfully")
except:
logging.error("Failed to send notification")