{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Playground\n",
    "\n",
    "This is a notebook to give a short overview of how to use the SumMed library. It's showing key features of SumMed in a Python notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "\n",
    "load_dotenv(\"../.env\")\n",
    "load_dotenv(\"../.env.testing\")\n",
    "\n",
    "import logging\n",
    "import os\n",
    "logger = logging.getLogger()\n",
    "logger.setLevel(logging.INFO)\n",
    "\n",
    "#os.environ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# import importlib\n",
    "import importlib\n",
    "import logging\n",
    "\n",
    "from abc import ABC, abstractmethod\n",
    "from datetime import datetime\n",
    "\n",
    "from importlib.metadata import version\n",
    "from typing import Dict, List, Optional, Union\n",
    "\n",
    "import spacy\n",
    "import requests\n",
    "\n",
    "\n",
    "from pydantic import BaseModel, validator\n",
    "\n",
    "\n",
    "# A bit confusion with client libs bing vs cognitive services\n",
    "# See: https://docs.microsoft.com/en-us/bing/search-apis/bing-custom-search/quickstarts/sdk/custom-search-client-library-python\n",
    "# https://github.com/Azure-Samples/cognitive-services-python-sdk-samples\n",
    "\n",
    "from azure.ai.formrecognizer import FormRecognizerClient\n",
    "from azure.ai.textanalytics import TextAnalyticsClient\n",
    "\n",
    "from azure.core.credentials import AzureKeyCredential\n",
    "from azure.storage.blob import (\n",
    "    BlobServiceClient,\n",
    "    BlobClient,\n",
    "    ContainerClient,\n",
    "    __version__,\n",
    ")\n",
    "\n",
    "from summed.data import PlatformConfig\n",
    "\n",
    "class IPlatform(ABC):\n",
    "    pass\n",
    "\n",
    "class SumMedPlatform(BaseModel, IPlatform):\n",
    "    \"\"\"\n",
    "    SumMed Platform , used to access global platform state like credentials, extensions.\n",
    "    \"\"\"\n",
    "\n",
    "    config: PlatformConfig = None\n",
    "    \n",
    "    # Internal fields for shared objects that we hold\n",
    "    _azure_blob_service_client: BlobServiceClient = None\n",
    "    _azure_form_recognizer_client: FormRecognizerClient = None\n",
    "    _azure_text_analytics_client: TextAnalyticsClient = None\n",
    "    _bing_custom_search_client: requests.Session = None\n",
    "    _dictionary_client:  requests.Session = None\n",
    "\n",
    "    # # This is just a REST client sessions (for now)\n",
    "\n",
    "\n",
    "    # # Register the spaCy language models. We hold one per language, Analyis is then execution (sub) pipelines with config, depending on task\n",
    "    # # Don't do spacy.load(...) more than once\n",
    "    # _spacy_models: Dict[str, spacy.Language] = {}\n",
    "    \n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:root:SumMed Platform instance created - '0.1.0' \n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "from azure.storage.blob import BlobServiceClient\n",
    "\n",
    "#from summed.data import PlatformConfig\n",
    "from summed.summed_platform import SumMedPlatform\n",
    "#from summed.translation import AzureTranslator\n",
    "\n",
    "platform = SumMedPlatform()\n",
    "\n",
    "conn_str = os.environ[\"SUMMED_AZURE_STORAGE_CONNECTION_STRING\"] #platform.config.azure_storage_connection_string\n",
    "container_name =\"summed-test-space\"\n",
    "\n",
    "client = BlobServiceClient.from_connection_string(conn_str=conn_str)\n",
    "container_client = client.get_container_client (container_name)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:azure.core.pipeline.policies.http_logging_policy:Request URL: 'https://summedsaasstorage.blob.core.windows.net/summed-test-space?restype=REDACTED'\n",
      "Request method: 'GET'\n",
      "Request headers:\n",
      "    'x-ms-version': 'REDACTED'\n",
      "    'Accept': 'application/xml'\n",
      "    'User-Agent': 'azsdk-python-storage-blob/12.11.0 Python/3.9.1 (Windows-10-10.0.22000-SP0)'\n",
      "    'x-ms-date': 'REDACTED'\n",
      "    'x-ms-client-request-id': '608ccdce-bd59-11ec-87b4-988d46995238'\n",
      "    'Authorization': 'REDACTED'\n",
      "No body was attached to the request\n",
      "INFO:azure.core.pipeline.policies.http_logging_policy:Response status: 404\n",
      "Response headers:\n",
      "    'Content-Length': '225'\n",
      "    'Content-Type': 'application/xml'\n",
      "    'Server': 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0'\n",
      "    'x-ms-request-id': 'ec22c1b3-501e-0044-7a66-511709000000'\n",
      "    'x-ms-client-request-id': '608ccdce-bd59-11ec-87b4-988d46995238'\n",
      "    'x-ms-version': 'REDACTED'\n",
      "    'x-ms-error-code': 'REDACTED'\n",
      "    'Date': 'Sat, 16 Apr 2022 07:46:50 GMT'\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what the\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print (f\"what the\")\n",
    "container_client.exists()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "client2 = platform.get_azure_blob_service_client()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "os.environ[\"SUMMED_AZURE_STORAGE_CONNECTION_STRING\"] == platform.config.azure_storage_connection_string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client2 = platform.get_azure_blob_service_client()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client2.exists()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "1c85340c5d174902c4c27171a0c22018dc56a7d9f941ff582c32af198be06318"
  },
  "kernelspec": {
   "display_name": "Python 3.9.1 ('.venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
