From 6b3c04d7593c7dd8d7c458f4380a55fcc6637ce2 Mon Sep 17 00:00:00 2001 From: panki27 Date: Fri, 8 Dec 2017 17:44:17 +0100 Subject: [PATCH] Small fixes regarding errorhandling --- certAlert.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/certAlert.py b/certAlert.py index 2e6480d..fd0d999 100644 --- a/certAlert.py +++ b/certAlert.py @@ -8,15 +8,12 @@ ERRSTR = '!!!!!!!!!!!!! ' # REMEMBER TO CHANGE THESE!!! TARGET_URL = 'https://www.cert-bund.de/overview/AdvisoryShort' -MEMORY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\certAlert\out.txt' +MEMORY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\certAlert\out.txt' KEY_FILE_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\keyfile' # To monitor more programs, simply add a string here -PROGRAMS = [u'Git', u'Chrome', u'OpenSSH', u'Java', u'Linux', u'Apache', u'Windows'] - - - +PROGRAMS = [u'Android', u'Git', u'Chrome', u'OpenSSH', u'Java', u'Linux', u'Apache', u'Windows'] # object to store a single cert alert class Advisory: @@ -35,6 +32,7 @@ class Advisory: print('link: ' + self.link) def startLogger(): + # todo: figure out how this works? # thanks to whoever i stole this from logger = logging.getLogger('certAlert') logger.setLevel(logging.DEBUG) @@ -52,7 +50,7 @@ def getHTML(url): print(ERRSTR + 'Check your internet connection or TARGET_URL.') sys.exit(ERRSTR + 'Stopping execution!') except: - e = sys.exc_info()[0] + e = sys.exc_info()[1] print(ERRSTR + 'Error getting Webpage!') print(e) sys.exit(ERRSTR + 'Stopping execution!') @@ -64,16 +62,18 @@ def readFile(path, lines = False): with open(path, 'r') as file: if(lines): contents = file.readlines() - else:contents = file.read() + else: + contents = file.read() file.close() except IOError: # this most likely means file not found. this can happen during the first run print(ERRSTR + 'Error reading file ' + path + '!') contents = '' except: - e = sys.exc_info()[0] + e = sys.exc_info()[1] print('An unknown error occured!') print(e) + contents = '' finally: return contents @@ -81,7 +81,7 @@ def main(): # this loads our API keys into memory from an external file which is specified above try: contents = readFile(KEY_FILE_PATH, True) - # extract just the text behind the equals sign + # extract just the text behind the equals sign API_KEY = contents[0].split("=",1)[1] USER_KEYS = contents[1].split("=",1)[1] # get rid of that pesky newline @@ -89,7 +89,7 @@ def main(): # now we split along semicolons to get single keys in a list USER_KEYS = USER_KEYS.split(";") except: - e = sys.exc_info()[0] + e = sys.exc_info()[1] print(e) print(ERRSTR + "I couldn't load your credentials. Did you specify your keyfile?") sys.exit(ERRSTR + 'Stopping execution!') @@ -120,7 +120,7 @@ def main(): key = key.rstrip() response = client.notify_single_device(registration_id=key, message_body=result.description, message_title=result.identifier) except: - e = sys.exc_info()[0] + e = sys.exc_info()[1] print(e) print("we fucked up!") result.debug() @@ -133,6 +133,5 @@ def main(): memFile.write(result.identifier + '\r') memFile.close() - if __name__ == '__main__': main() \ No newline at end of file