retrieving.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. import os
  7. project_id = os.getenv('PROJECT_ID')
  8. bucket_name = os.getenv('BUCKET_NAME')
  9. location = os.getenv('LOCATION')
  10. key_path = os.getenv('SA_KEY_PATH')
  11. dataset_name = os.getenv('BQ_DATASET_NAME')
  12. table_name = os.getenv('BQ_TABLE_NAME')
  13. case_id = os.getenv('TEST_CASE')
  14. credentials = service_account.Credentials.from_service_account_file(key_path)
  15. bq_client = bigquery.Client(credentials=credentials)
  16. datastore_client = datastore.Client(credentials=credentials)
  17. # Returns a list of results
  18. try:
  19. results_lst = returnQueryResults(bq_client, project_id, dataset_name, table_name, case_id)
  20. logging.info("Here is the result of the test query: \n {}".format(results_lst))
  21. except Exception, e:
  22. logging.error("Error", e)
  23. try:
  24. filter_dict = {'Sign or Symptom':['onset symptoms', "chills"]}
  25. results = getCases(datastore_client, filter_dict, limit=10)
  26. logging.info("Here is the result of the test query: \n {}".format(results))
  27. except Exception, e:
  28. logging.error("Error", e)