Skip to content

Commit

Permalink
fix: Market Activity report particulary parsed (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam2502 authored May 16, 2024
1 parent bd0824c commit e9da3c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions nsedt/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

import logging

from io import BytesIO
import pandas as pd

from nsedt.utils import get_cookies, fetch_csv, format_date, fetch_zip
from nsedt.resources.constants import (
REPORT_URL, MARKET_ACTIVITY_REPORT,
BHAV_COPY_REPORT, SEC_BHAV_COPY_REPORT, NSCCL_REPORTS, NSCCL_VOLT)


log = logging.getLogger("root")

# tbd
Expand All @@ -23,8 +27,8 @@ def get_market_activity_report(date: str):
Args:\n
date (str): date for which to download market activity report\n
Returns:
string: string content of the file as right now its not possible
to format the content to json or pandas df
df = Returns dataframe for market activity report for sectors
for the given date
Expects:
date to be in format of "dd-mm-yyyy" eg: 30-04-2024
all other cases will be invalidated
Expand All @@ -35,8 +39,11 @@ def get_market_activity_report(date: str):

cookies = get_cookies()
url = f"{REPORT_URL}{MARKET_ACTIVITY_REPORT}{date}.csv"
return fetch_csv(url, cookies, response_type="raw")

response = fetch_csv(url, cookies, response_type="raw")
df = pd.read_csv(BytesIO(response), skiprows=8)
df.drop(columns=['Unnamed: 0'], inplace=True)
df = df[:77]
return df

def get_volatility_report(date: str, response_type: str="panda_df"):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_get_market_activity_report():
Test get market activity report for a given date
"""
data = get_market_activity_report(date=REPORT_DATE)
assert isinstance(data, bytes)
assert isinstance(data, pd.DataFrame)


def test_get_bhav_copy_zip():
Expand Down

0 comments on commit e9da3c6

Please sign in to comment.