retrieving.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from google.cloud import storage, bigquery, datastore
  2. from google.oauth2 import service_account
  3. from utils.bq_fcn import returnQueryResults, constructQuery
  4. from utils.ner_fcn import getCases
  5. import os
  6. import logging
  7. logging.getLogger().setLevel(logging.INFO)
  8. project_id = os.getenv('PROJECT_ID')
  9. bucket_name = os.getenv('BUCKET_NAME')
  10. location = os.getenv('LOCATION')
  11. key_path = os.getenv('SA_KEY_PATH')
  12. dataset_name = os.getenv('BQ_DATASET_NAME')
  13. table_name = os.getenv('BQ_TABLE_NAME')
  14. case_id = os.getenv('TEST_CASE')
  15. credentials = service_account.Credentials.from_service_account_file(key_path)
  16. bq_client = bigquery.Client(credentials=credentials)
  17. datastore_client = datastore.Client(credentials=credentials)
  18. # Returns a list of results
  19. try:
  20. query = constructQuery(column_lst=['*'], case_id='case23')
  21. results_lst = returnQueryResults(bq_client, query)
  22. logging.info("Here is the result of the BigQuery test case: \n")
  23. logging.info("======================================START======================================")
  24. logging.info(results_lst)
  25. logging.info("======================================FINISH======================================")
  26. except Exception as e:
  27. logging.error("Error", e)
  28. try:
  29. filter_dict = {'Disease or Syndrome': ['heart failure']}
  30. results = getCases(datastore_client, filter_dict, limit=10)
  31. logging.info("Here is the result of the Datastore test case: \n")
  32. logging.info("======================================START======================================")
  33. logging.info(results)
  34. logging.info("======================================FINISH======================================")
  35. except Exception as e:
  36. logging.error("Error", e)