Skip to content

Commit

Permalink
Added code to read standard datasets only from google sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
venu-sambarapu-DS committed Jun 3, 2024
1 parent 101bb90 commit 4e6455b
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions app/api/api_v1/routers/dictionary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pandas as pd
from fastapi import APIRouter, HTTPException, status
from fastapi.encoders import jsonable_encoder
import io
import requests
from fastapi.responses import JSONResponse

from app.core.config import CORE_FOLDER, Settings
Expand All @@ -12,13 +14,26 @@
dictionary_router = router = APIRouter()


g_sheet_session = requests.Session()
g_sheet_response = g_sheet_session.get("https://docs.google.com/spreadsheets/d/1NEsFJGr5IHsrIakGgeNFUvz5zpLOadh_vDH7Apqmv9E/gviz/tq?tqx=out:csv&sheet=master_dictionaries")
g_sheet_bytes_data = g_sheet_response.content
data = pd.read_csv(io.StringIO(g_sheet_bytes_data.decode('utf-8')))
print("reading data from google sheet@@@@")
# data.rename(
# columns={
# "country_standard_name": "country",
# "unique_standard_airline_name": "airline",
# "standard_disease_name": "disease",
# "psu_companies": "psu",
# }
# )
# print(data.columns.tolist())


@router.get("/", summary="Get all Saved Entities csv file name")
async def get_entity_names():
# List down all the csv files present in the config folder
return [
csv_file.name.replace(".csv", "")
for csv_file in CORE_FOLDER.glob("**/*.csv")
]
return data.columns.tolist()


@router.get(
Expand All @@ -27,9 +42,9 @@ async def get_entity_names():
response_class=JSONResponse,
)
async def get_entity_data(entity: str):
entity_df = pd.read_csv(CORE_FOLDER / f"{entity}.csv")
entity_df = data[[entity]].dropna()
# to avoid json conversion error
entity_df = entity_df.fillna("")
# entity_df = entity_df.fillna("")

# convert to json
json_compatible_item_data = jsonable_encoder(
Expand Down

0 comments on commit 4e6455b

Please sign in to comment.