コード例 #1
0
ファイル: server.py プロジェクト: alimulhuda/design-project
    def sendNotifications(self):
        log.msg("MonitorService.sendNotifications(): Sending out notifications");

        from time import time
        from consider.notifications import options

        for user in self.users:
            for webPage in user.webPages:
                notificationOptions = user.webPages[webPage]
                log.msg(str(notificationOptions))
                notificationTypes = notificationOptions.getNotificationTypes()
                if (options.NOTIFICATION_TYPE_EMAIL in notificationTypes) or (options.NOTIFICATION_TYPE_SMS in notificationTypes):
                    lastSeen = user.webPages[webPage].getLastSeenTimestamp(options.NOTIFICATION_TYPE_EMAIL)
                    frequency = user.webPages[webPage].getFrequency()
                    if lastSeen != None:
                        # only check if we havent checked it for a while
                        # finout out from user's options how much delay
                        if (int(time()) - int(lastSeen)) <  options.getDelayForFrequency(frequency):
                            continue
                    user.webPages[webPage].setLastSeenTimestamp(options.NOTIFICATION_TYPE_EMAIL, time())

                    diff = self.getNewDiff(user.name, webPage, options.NOTIFICATION_TYPE_EMAIL)
                    if options.NOTIFICATION_TYPE_EMAIL in notificationTypes:
                        diff.addCallback(self._sendEmail, args=[user, webPage])
                        diff.addErrback(self._sendEmailError)
                    if options.NOTIFICATION_TYPE_SMS in notificationTypes:
                        log.msg('Notifying ' + user.name + ' about ' +
                                str(webPage) + ' through sms')
                else:
                    log.msg('Skipping ' + str(webPage))
コード例 #2
0
    def checkForUpdates(self, forced):
        from time import time

        if debug.verbose:
            print('DEBUG: Check for updates')

        oldDiff = self.diff
        self.diff = {}

        server = xmlrpclib.Server(self.settings.serverAddress)
        webPages = self.settings.getWebPages();
        webPagesToCheck = [ webPage for webPage in webPages
                    if options.NOTIFICATION_TYPE_CLIENT in self.settings.webPages[webPage].getNotificationTypes() ]
        for webPage in webPagesToCheck:
            if debug.verbose:
                print('DEBUG: last seen = ' + 
                        str(webPages[webPage].getLastSeenTimestamp(options.NOTIFICATION_TYPE_CLIENT)))
            lastSeen = webPages[webPage].getLastSeenTimestamp(options.NOTIFICATION_TYPE_CLIENT)
            frequency = webPages[webPage].getFrequency()
            if debug.verbose:
                print('DEBUG: frequency: ' + str(frequency))
            if lastSeen != None:
                # only check if we havent checked it for a while
                # finout out from user's options how much delay
                if (int(time()) - int(lastSeen)) <  options.getDelayForFrequency(frequency):
                    continue
            webPages[webPage].setLastSeenTimestamp(options.NOTIFICATION_TYPE_CLIENT, time())
            if debug.verbose:
                print('DEBUG: Checking ' + str(webPage))
            diff = server.getNewDiff(self.settings.username, webPage)
            if diff == None or diff == '':
                continue
            if debug.verbose:
                print('DEBUG: diff from server \n' +  diff)
            self.diff[webPage] = diff

        updatedWebPages = [ webPage for webPage in self.diff]

        # keep the older entries, but replace the newer entries 
        newDiff = self.diff
        self.diff = oldDiff
        for webPage in newDiff:
            self.diff[webPage] = newDiff[webPage]

        if debug.verbose:
            print('DEBUG: Done checking for updates')
        return updatedWebPages