From 39b4d7191e10685155c0dff9e49eeada5424d932 Mon Sep 17 00:00:00 2001 From: Pratik Anand <13189088+pratik141@users.noreply.github.com> Date: Sun, 11 Jun 2023 03:12:53 +0200 Subject: [PATCH] Update workflow --- .github/workflows/pylint.yml | 6 +++++- .pylintrc | 12 ++++++++++++ README.md | 32 +++++++++++++++++++++++++++++++- nsedt/equity.py | 10 +++++----- nsedt/utils/__init__.py | 12 ++++++------ nsedt/utils/data_format.py | 2 +- setup.py | 2 +- 7 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 .pylintrc diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 383e65c..c99e38b 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,17 +7,21 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.10"] steps: - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip pip install pylint + pip install -r requirements.txt + - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..8f8b325 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,12 @@ +[DESIGN] + +# Maximum number of locals for function / method body +max-locals=25 + +# Maximum number of arguments for function / method +max-args=10 + +[FORMAT] + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$|^\s*(\w*\s*=\s*)?(\"|\').*(\"|\'),?\s*$ \ No newline at end of file diff --git a/README.md b/README.md index d09d09a..e79a8c6 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ symbol TCS atoSellQty NaN NaN NaN ... NaN NaN 491 #get_companyinfo json format -{"info":{"symbol":"TCS","companyName":"Tata Consultancy Services Limited","industry":"COMPUTERS - SOFTWARE","activeSeries":["EQ"],"debtSeries":[],"tempSuspendedSeries":[],"isFNOSec":true,"isCASec":false,"isSLBSec":true,"isDebtSec":false,"isSuspended":false,"isETFSec":false,"isDelisted":false," ......} +{"info":{"symbol":"TCS","companyName":"Tata Consultancy Services Limited","industry":"COMPUTERS - SOFTWARE","activeSeries":["EQ"],"debtSeries":[],"tempSuspendedSeries":[],"isFNOSec":true,"isCASec":false,"isSLBSec":true,"isDebtSec":false,"isSuspended":false,"isETFSec":false,"isDelisted":false, ......} #get_marketstatus @@ -66,3 +66,33 @@ atoSellQty NaN ``` +--- + +# API Documentation + +## Functions + +### get_companyinfo + +Function description goes here. + +### get_marketstatus + +Function description goes here. + +### get_price + +Function description goes here. + +### get_corpinfo + +Function description goes here. + +### get_event + +Function description goes here. + +### get_chartdata + +Function description goes here. + diff --git a/nsedt/equity.py b/nsedt/equity.py index 5f13c6a..81fafff 100644 --- a/nsedt/equity.py +++ b/nsedt/equity.py @@ -43,7 +43,7 @@ def get_companyinfo( params["symbol"] = symbol url = base_url + event_api + urllib.parse.urlencode(params) - data = utils.fetch_url(url, cookies, key="info") + data = utils.fetch_url(url, cookies) if response_type == "panda_df": return data @@ -106,8 +106,7 @@ def get_price( current_window_end = current_window_start + window_size # check if the current window extends beyond the end_date - if current_window_end > end_date: - current_window_end = end_date + current_window_end = min(current_window_end, end_date) if input_type == "stock": params = { @@ -126,7 +125,8 @@ def get_price( result = pd.DataFrame() with concurrent.futures.ThreadPoolExecutor(max_workers=cns.MAX_WORKERS) as executor: future_to_url = { - executor.submit(utils.fetch_url, url, cookies): url for url in url_list + executor.submit(utils.fetch_url, url, cookies, "data"): url + for url in url_list } concurrent.futures.wait(future_to_url, return_when=ALL_COMPLETED) for future in concurrent.futures.as_completed(future_to_url): @@ -135,7 +135,7 @@ def get_price( dataframe = future.result() result = pd.concat([result, dataframe]) except Exception as exc: - logging.error(f"{url} got exception: {exc}. Please try again later.") + logging.error("%s got exception: %s. Please try again later.", url, exc) raise exc return data_format.price(result) diff --git a/nsedt/utils/__init__.py b/nsedt/utils/__init__.py index 4ca9869..f057f84 100644 --- a/nsedt/utils/__init__.py +++ b/nsedt/utils/__init__.py @@ -44,7 +44,7 @@ def get_cookies(): return response.cookies.get_dict() -def fetch_url(url, cookies, key="data"): +def fetch_url(url, cookies, key=None): """ Args: url (str): URL to fetch @@ -58,9 +58,9 @@ def fetch_url(url, cookies, key="data"): response = requests.get(url, timeout=30, headers=get_headers(), cookies=cookies) if response.status_code == 200: json_response = json.loads(response.content) - try: - return pd.DataFrame.from_dict(json_response[key]) - except: + if key is None: return pd.DataFrame.from_dict(json_response) - else: - raise ValueError("Please try again in a minute.") + + return pd.DataFrame.from_dict(json_response[key]) + + raise ValueError("Please try again in a minute.") diff --git a/nsedt/utils/data_format.py b/nsedt/utils/data_format.py index bfda38f..a64ae9c 100644 --- a/nsedt/utils/data_format.py +++ b/nsedt/utils/data_format.py @@ -31,7 +31,7 @@ def price(result): ] try: result = result[columns_required] - except: + except: # pylint: disable=W0702 return result result = result.set_axis( [ diff --git a/setup.py b/setup.py index 4a9f6a5..9904eac 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ], )