Skip to content

Commit

Permalink
Make running the importer a function
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Feb 27, 2015
1 parent 6675816 commit 97872c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions rxnorm_link_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(self):
db_bucket = os.environ.get('MONGO_BUCKET')
db_bucket = db_bucket if db_bucket else 'rxnorm'

import pymongo # imported here so it's only imported when using Mongo
conn = pymongo.MongoClient(host=db_host, port=db_port)
db = conn[db_name]

Expand Down Expand Up @@ -181,20 +182,13 @@ def __str__(self):
return 'CSV file "{}"'.format(self.csv_file)


if '__main__' == __name__:
logging.basicConfig(level=logging.INFO)

if 'did' != os.environ.get('DID_SOURCE_FOR_SETUP', 0):
logging.error('You should use "rxnorm_link_run.sh" in order to run the linking process')
sys.exit(1)

# create handler and run
ex_type = os.environ.get('EXPORT_TYPE')
def runLinking(ex_type):
""" Create the desired handler and run import.
"""
handler = DebugDocHandler()
if ex_type is not None and len(ex_type) > 0:
try:
if 'mongo' == ex_type:
import pymongo
handler = MongoDocHandler()
elif 'couch' == ex_type:
# import couchbase
Expand All @@ -211,3 +205,13 @@ def __str__(self):

print('-> Processing to {}'.format(handler))
runImport(doc_handler=handler)


if '__main__' == __name__:
logging.basicConfig(level=logging.INFO)

cmd_arg = sys.argv[1] if len(sys.argv) > 1 else None
ex_type = os.environ.get('EXPORT_TYPE') or cmd_arg

runLinking(ex_type)

4 changes: 2 additions & 2 deletions rxnorm_link_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# to make it simple we include the variables here instead of creating yet another file

# export type, supported are "csv" and "mongo" and "sqlte" so far
# export type, supported are: "csv", "mongo", "sqlite"
# if run without setting a type will simply print to console
export EXPORT_TYPE=

# MongoDB parameters
Expand All @@ -19,5 +20,4 @@ export SQLITE_FILE='databases/rxnorm.db'
# TODO: add a Couchbase version

# run the setup script with these environment variables
export DID_SOURCE_FOR_SETUP='did'
python3 rxnorm_link_run.py

0 comments on commit 97872c3

Please sign in to comment.