Skip to content

Instantly share code, notes, and snippets.

View coreindustries's full-sized avatar

Corey Szopinski coreindustries

View GitHub Profile
@coreindustries
coreindustries / unhandled_exception.py
Created January 14, 2020 21:22
Python: unhandled exception handler
def handle_uncaught_exceptions(e, value, tb):
""" https://stackoverflow.com/questions/8050775/using-pythons-logging-module-to-log-all-exceptions-and-errors/8054179#8054179 """
log.exception(f"API Uncaught exception: {e}{value}")
traceback.print_tb(tb)
sys.excepthook = handle_uncaught_exceptions
@coreindustries
coreindustries / send_ses_email.py
Created December 27, 2019 18:26
Python: send email via AWS SES
def send_email(subject="Website:", to="[email protected]", body={'field': 'empty'}):
"""
GIVEN A SUBJECT, TO ADDRESS AND AN OBJECT,
SEND THE EMAIL VIA AWS SIMPLE EMAIL SERVICE
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ses.html
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html
"""
# FROM email address. A constant defined elsewhere
@coreindustries
coreindustries / validate_email_address.py
Last active December 27, 2019 18:21
Python: validate email address
def validate_email(email_address):
"""
Validate an email address.
We selected a "simple" validation with has a bias toward
letting more edge cases through rather than block them.
We want the feedback.
Returns True if the email is valid. False is not.
@coreindustries
coreindustries / urllib_logging.py
Last active December 30, 2019 18:23
Python: enable/disable urllib logging
from http.client import HTTPConnection
# enable/disable urllib logging
HTTPConnection.debuglevel = 0
requests_log = logging.getLogger("urllib3")
requests_log.setLevel(logging.INFO)
requests_log.propagate = True