예제 #1
0
class Notifier(object):
    def __init__(self):
        self.notificationsettings = NotificationSettings()
        self.tweets = []
        self.notifiers = []
        self.notifiers.append(EmailNotifier())
        self.notifiers.append(TelegramNotifier())

    def ontweetreceived(self, tweet):
        self._refresh_settings()
        self.tweets.append(Tweet(tweet))
        self._remove_obsolete_tweets()
        if(len(self.tweets) >= self.notificationsettings.threshold):
            self._notify()
            self.tweets = []

    def _remove_obsolete_tweets(self):
        obsolete = []
        for tweet in self.tweets:
            diff = datetime.utcnow().replace(tzinfo=pytz.UTC) - tweet.datetime
            if((diff.total_seconds() / 60) > self.notificationsettings.thresholdtime):
                obsolete.append(tweet)

        for old in obsolete:
            self.tweets.remove(old)

    def _notify(self):
        for notifier in self.notifiers:
            notifier.send_notification(self.tweets)

    def _refresh_settings(self):
        self.notificationsettings.refresh()
예제 #2
0
 def __init__(self):
     self.notificationsettings = NotificationSettings()
     self.tweets = []
     self.notifiers = []
     self.notifiers.append(EmailNotifier())
     self.notifiers.append(TelegramNotifier())