Small fixes regarding errorhandling
This commit is contained in:
parent
5edc52bec8
commit
6b3c04d759
23
certAlert.py
23
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()
|
Loading…
Reference in New Issue
Block a user