Added basic exception handling
This commit is contained in:
parent
9d1e1396d7
commit
a72100ee23
28
certAlert.py
28
certAlert.py
@ -1,8 +1,6 @@
|
|||||||
#!/bin/env/python
|
#!/bin/env/python
|
||||||
import datetime
|
import datetime, sys, re, urllib2
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
|
||||||
import urllib2
|
|
||||||
|
|
||||||
TARGET_URL = 'https://www.cert-bund.de/overview/AdvisoryShort'
|
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'
|
||||||
@ -22,8 +20,12 @@ class Advisory:
|
|||||||
print('desc: ' + self.description)
|
print('desc: ' + self.description)
|
||||||
print('link: ' + self.link)
|
print('link: ' + self.link)
|
||||||
|
|
||||||
|
try:
|
||||||
response = urllib2.urlopen(TARGET_URL)
|
response = urllib2.urlopen(TARGET_URL)
|
||||||
|
except:
|
||||||
|
e = sys.exc_info()[0]
|
||||||
|
print('Error getting Webpage!\r\n' + e)
|
||||||
|
sys.exit('Stopping execution!')
|
||||||
html = response.read()
|
html = response.read()
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
|
||||||
@ -31,10 +33,18 @@ results = []
|
|||||||
for adv in soup.find_all('tr', {'class' : re.compile('search-result-*')}):
|
for adv in soup.find_all('tr', {'class' : re.compile('search-result-*')}):
|
||||||
x = Advisory(adv)
|
x = Advisory(adv)
|
||||||
results.append(x)
|
results.append(x)
|
||||||
|
try:
|
||||||
with open(MEMORY_PATH, 'r') as memFile:
|
with open(MEMORY_PATH, 'r') as memFile:
|
||||||
checkedIDs = memFile.read()
|
checkedIDs = memFile.read()
|
||||||
memFile.close()
|
memFile.close()
|
||||||
|
except IOError:
|
||||||
|
print('Error reading memory file!')
|
||||||
|
print('Continuing without list of checked IDs...')
|
||||||
|
checkedIDs = ''
|
||||||
|
except:
|
||||||
|
e = sys.exc_info()[0]
|
||||||
|
print('An unknown error occured!')
|
||||||
|
print(e)
|
||||||
for result in results:
|
for result in results:
|
||||||
if result.risk > 3:
|
if result.risk > 3:
|
||||||
for prog in PROGRAMS:
|
for prog in PROGRAMS:
|
||||||
@ -48,7 +58,3 @@ with open(MEMORY_PATH, 'w') as memFile:
|
|||||||
for result in results:
|
for result in results:
|
||||||
memFile.write(result.identifier + '\r\n')
|
memFile.write(result.identifier + '\r\n')
|
||||||
memFile.close()
|
memFile.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#print(soup.prettify())
|
|
Loading…
Reference in New Issue
Block a user