Skip to content

Commit

Permalink
fixed issues #18,#19
Browse files Browse the repository at this point in the history
  • Loading branch information
frdougal committed Dec 10, 2018
1 parent f405b3b commit 47c6352
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ lazy=False
# Set the logging level to one of these options: ERROR, WARNING, INFO, DEBUG
logging_level=ERROR

# Change the location of the log file. By default, the log file is placed in the directory where redcapToCdm.py is executing.
This setting is OPTIONAL.
logging_directory=''
36 changes: 22 additions & 14 deletions redcapToCdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#initialize a dictionary with all the variables relating to the REDCAP section
#This allows the code to loop through the section while loading the variables into the dictionary
dictRedcapSettings = {'api_url' : None, 'redcap_project_info' : None, 'verify_ssl' : True, 'lazy' : False,
'load_text_fields' : False, 'logging_level' : 'INFO'}
'load_text_fields' : False, 'logging_level' : 'INFO', 'logging_directory': ''}

# a dictionary to manage the data types found in the pro_cm table
dictPROCMTableDataTypes = {'pro_date' : 'date', 'pro_response_num' : 'number', 'pro_measure_score' : 'number', 'pro_measure_theta' : 'number',
Expand Down Expand Up @@ -80,7 +80,6 @@ def loadConfigFile():
"""
config = ConfigParser.ConfigParser()
try:
logging.info("Starting loading config.ini")
config.read('config.ini')
for k in dictDatabaseSettings.keys():
dictDatabaseSettings[k] = config.get('DATABASE', k)
Expand All @@ -95,6 +94,27 @@ def loadConfigFile():
dictRedcapSettings['verify_ssl'] = bool(dictRedcapSettings['verify_ssl'])
dictRedcapSettings['lazy'] = bool(dictRedcapSettings['lazy'])
dictRedcapSettings['load_text_fields'] = bool(dictRedcapSettings['load_text_fields'])

logging_directory = ''
if 'logging_directory' in dictRedcapSettings:
logging_directory = str(dictRedcapSettings['logging_directory'])

loggingfilename = os.path.join(logging_directory, 'redcap.log.' + str(os.getpid()))

logging.basicConfig(filename=loggingfilename,level=logging.DEBUG, format='%(asctime)s: %(levelname)s - %(message)s')

logging.info("Starting loading config.ini")
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
logging.getLogger('').addHandler(console)

# suppress the extraneous HTTP messages from the logs
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

today = datetime.datetime.now()
logging.info('Starting REDCap ETL to CDM Process: ' + today.strftime('%m/%d/%Y %I:%M'))
level = logging.getLevelName(str(dictRedcapSettings['logging_level']))
if level == None:
level = logging.INFO
Expand Down Expand Up @@ -705,18 +725,6 @@ def etlProject(dbobj, project_info):
if __name__ == "__main__":
# use this command to disable the InsecurePlatformWarning (see http://stackoverflow.com/questions/29099404/ssl-insecureplatform-error-when-using-requests-package)
requests.packages.urllib3.disable_warnings()
logging.basicConfig(filename='redcap.log.' + str(os.getpid()),level=logging.DEBUG, format='%(asctime)s: %(levelname)s - %(message)s')
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
logging.getLogger('').addHandler(console)

# suppress the extraneous HTTP messages from the logs
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

today = datetime.datetime.now()
logging.info('Starting REDCap ETL to CDM Process: ' + today.strftime('%m/%d/%Y %I:%M'))

loadConfigFile()
if dictDatabaseSettings['dbms'] == "Oracle":
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
requests==2.7.0
requests==2.20.0
semantic-version==2.4.2
python-dateutil==2.6.1

0 comments on commit 47c6352

Please sign in to comment.