retrieving.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from google.cloud import storage, bigquery, datastore
  2. from google.oauth2 import service_account
  3. from covid19_ISMIR.utils.bq_fcn import returnQueryResults
  4. from covid19_ISMIR.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. project_id=project_id)
  17. datastore_client = datastore.Client(credentials=credentials,
  18. project_id=project_id)
  19. # Returns a list of results
  20. try:
  21. results_lst = returnQueryResults(bq_client, project_id, dataset_name, table_name, case_id)
  22. logging.info("Here is the result of the test query: \n {}".format(results_lst))
  23. except Exception, e:
  24. logging.error("Error", e)
  25. try:
  26. filter_dict = {'Sign or Symptom':['onset symptoms', "chills"]}
  27. results = getCases(datastore_client, filter_dict, limit=10)
  28. logging.info("Here is the result of the test query: \n {}".format(results))
  29. except Exception, e:
  30. logging.error("Error", e)