import sys |
import sys |
import os |
import os |
sys.path.insert(0, os.path.join(os.path.dirname(__file__) or '.', '../')) |
sys.path.insert(0, os.path.join(os.path.dirname(__file__) or '.', '../')) |
import genericScrapers |
import genericScrapers |
|
import traceback |
|
try: |
|
import amonpy |
|
amonpy.config.address = 'http://amon_instance:port' |
|
amonpy.config.secret_key = 'the secret key from /etc/amon.conf' |
|
amon_available = True |
|
except ImportError: |
|
amon_available = False |
|
|
class ScraperImplementation(genericScrapers.GenericPDFDisclogScraper): |
class ScraperImplementation(genericScrapers.GenericPDFDisclogScraper): |
|
|
def __init__(self): |
def __init__(self): |
super(ScraperImplementation, self).__init__() |
super(ScraperImplementation, self).__init__() |
|
|
|
|
if __name__ == '__main__': |
if __name__ == '__main__': |
print 'Subclass:', issubclass(ScraperImplementation, |
print 'Subclass:', issubclass(ScraperImplementation, |
genericScrapers.GenericPDFDisclogScraper) |
genericScrapers.GenericPDFDisclogScraper) |
print 'Instance:', isinstance(ScraperImplementation(), |
print 'Instance:', isinstance(ScraperImplementation(), |
genericScrapers.GenericPDFDisclogScraper) |
genericScrapers.GenericPDFDisclogScraper) |
ScraperImplementation().doScrape() |
try: |
|
ScraperImplementation().doScrape() |
|
except Exception, err: |
|
sys.stderr.write('ERROR: %s\n' % str(err)) |
|
print ‘Error Reason: ‘, err.__doc__ |
|
print ‘Exception: ‘, err.__class__ |
|
print traceback.format_exc() |
|
if amon_available: |
|
data = { |
|
'exception_class': '', |
|
'url': '', |
|
'backtrace': ['exception line ', 'another exception line'], |
|
'enviroment': '', |
|
|
|
# In 'data' you can add request information, session variables - it's a recursive |
|
# dictionary, so you can literally add everything important for your specific case |
|
# The dictionary doesn't have a specified structure, the keys below are only example |
|
'data': {'request': '', 'session': '', 'more': ''} |
|
|
|
} |
|
|
|
amonpy.exception(data) |
|
pass |
|
|