Skip to content

Commit

Permalink
Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pratik141 committed Jun 11, 2023
1 parent bdf020e commit 39b4d71
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
12 changes: 12 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -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*(# )?<?https?://\S+>?$|^\s*(\w*\s*=\s*)?(\"|\').*(\"|\'),?\s*$
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

10 changes: 5 additions & 5 deletions nsedt/equity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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):
Expand All @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions nsedt/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
2 changes: 1 addition & 1 deletion nsedt/utils/data_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def price(result):
]
try:
result = result[columns_required]
except:
except: # pylint: disable=W0702
return result
result = result.set_axis(
[
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

0 comments on commit 39b4d71

Please sign in to comment.