retrieving.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from google.cloud import storage, bigquery, datastore
  2. from google.oauth2 import service_account
  3. from utils.bq_fcn import returnQueryResults
  4. from utils.ner_fcn import getCases
  5. import logging
  6. logging.getLogger().setLevel(logging.INFO)
  7. import os
  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. results_lst = returnQueryResults(bq_client, project_id, dataset_name, table_name, case_id)
  21. logging.info("Here is the result of the test query: \n {}".format(results_lst))
  22. except Exception as e:
  23. logging.error("Error", e)
  24. try:
  25. filter_dict = {'Sign or Symptom':['onset symptoms', "chills"]}
  26. results = getCases(datastore_client, filter_dict, limit=10)
  27. logging.info("Here is the result of the test query: \n {}".format(results))
  28. except Exception as e:
  29. logging.error("Error", e)