Пример #1
0
    def run(self):
        if self.debug:
            print("Running in Debug Mode")

        for site in self.config.getSites():
            try:
                regex = self.config.getSites()[site]['regex']
            except KeyError:
                regex = None

            url = self.config.getSites()[site]['url']

            obj = TmpFileHandler(site)
            fetcher = FetchSite(url)

            if regex is not None:
                if self.debug:
                    print("Using Regex for " + site)
                fetcher.useRegex(regex)
                if self.debug:
                    print("Regex Result (first 100 chars): " + fetcher.getData()[0:100])

            if obj.getHash() is 'init':
                if self.debug:
                    print("First Time fetching " + site)
                obj.setHash(fetcher.getHash())

            if obj.getHash() != fetcher.getHash():
                if self.debug:
                    print(
                          "Hash from File: %s \nHash from Site: %s" %
                          (obj.getHash(), fetcher.getHash())
                          )

                # Mail senden und neuen Hash speichern
                obj.setHash(fetcher.getHash())

                for contact in self.config.getContacts():
                    to = self.config.getContacts()[contact]['email']
                    if site in  self.config.getContacts()[contact]['sites']:
                        self.mail.sendMail(to, url, site)
Пример #2
0
 def testTmpFileHandler(self):
     fh = TmpFileHandler("test")
     fh.setHash("123")
     tmp = fh.getHash()
     fh.delete()
     self.assertEquals(tmp, "123", "")