コード例 #1
0
def main():
    '''Run tests of API functions. View results in testlog.txt.
  Takes two command-line arguments: two email addresses (can be fake).
  Note: will attempt to send emails via local SMTP!
  '''
    if len(sys.argv) != 3:
        print 'Takes two email addresses as command-line args (can be fake).' \
              '\nNote: will attempt to use smtp to send to these addresses.'
        sys.exit(1)
    print 'Command-line arguments are: ' + str(sys.argv)
    print 'Will write logs to testlog.txt'

    # create_logger tests
    # -------------------
    print "Testing create_logger function."
    logger = kickshaws.create_logger('testlog.txt', 'Test')
    # strings
    logger.info('Kickshaws library!')
    logger.error('An error! Don\'t worry!')
    # integers
    logger.info(1147)
    logger.error(1147)
    # exception
    try:
        raise Exception("Raising exception on purpose.")
    except Exception, ex:
        logger.error(ex)
コード例 #2
0
import sys
import kickshaws as ks
import redcaplib as rc
from common import *

__all__ = ['handle']

FROM_EMAIL = 'X'
TO_EMAIL = 'X'

log = ks.create_logger(get_log_filepath(), __name__)


def handle(req):
    try:
        pyld = rc.parse_det_payload(req['data'])
        log.info('Parsed contents of DET payload: ' + str(pyld))
        msg = 'Received trigger payload from REDCap. Details: \n' \
              'REDCap Server IP: {} \n' \
              'Project ID: {} \n' \
              'Record ID: {} \n' \
              ''.format(req['client_ip'], pyld['project_id'], pyld['record'])
        log.info('Sending email, body is: \n' + msg)
        ks.send_email(FROM_EMAIL, TO_EMAIL, 'Transmitter Test Email', msg)
        return {'status': 200}
    except Exception, e:
        log.error('Got error; returning status 500; details: ' + str(e))
        return {'status': 500}
コード例 #3
0
ファイル: main.py プロジェクト: djb2188/ingester
#-----------------------------------------------------------------------------
# The next 2 statements prevent the following error when inserting into db:
#   "'ascii' codec can't encode character ..."
# Reference: https://stackoverflow.com/a/31137935
reload(sys)
sys.setdefaultencoding('utf-8')

#-----------------------------------------------------------------------------
# init

# Total of [row w/ col titles] + [4 non-csv rows that HealthPro csv includes]
HP_CSV_NONDATA_ROWCOUNT = 5

# Create log object.
log = ks.create_logger('hpimporter.log', 'main-logger')

# Load configuration info from config file.
config_fname = 'enclave/healthproimporter_config.json'
cfg = {}
with open(config_fname, 'r') as f: cfg = json.load(f)
consortium_tag = cfg['consortium_tag']
inbox_dir = cfg['inbox_dir']
archive_dir = cfg['archive_dir']
db_info = cfg['db_info']
healthpro_table_name = cfg['healthpro_table_name'] 
metadata_table_name = cfg['metadata_table_name']
redcap_table_name = cfg['redcap_table_name']
redcap_job_name = cfg['redcap_job_name']
from_email = cfg['from_email'] 
to_email = cfg['to_email']