retrieving.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 test query: \n {}".format(results_lst))
  23. except Exception as 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 as e:
  30. logging.error("Error", e)