Merge commit '8bf92c04ed0e9fe72699763a3a65f4a27d93a4b5' as 'utils_v2'

This commit is contained in:
2024-12-04 13:35:29 +05:30
132 changed files with 101546 additions and 0 deletions
View File
+232
View File
@@ -0,0 +1,232 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Thursday, 28th Nov., 2024
OBJECTIVE:
To provide a way to retrieve dates of important events like financial-results, stock-splits, fund-raising, etc.
from NSE's portal.
NOTE: This method involves web scraping. It is good for proof-of-concept development, but it is recommended that
more professional data-sources be used when the product starts becoming mature.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# System-level activities:
import io
# My utils:
from utils_v2.string import json
from utils_v2.date_time import date_time
# NSE-related utils:
from utils_v2.nse.base import AsyncNSEBase
from utils_v2.nse.models.data.api_call import NSEApiResponse
# To make REST-ful API calls:
import httpx
# To work with date and time:
import datetime
# To work with datatypes:
from typing import Any, List
# For asynchronous activities:
import asyncio
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class NSECorporateEventCalendar(AsyncNSEBase):
def __init__(
self,
http_client: httpx.AsyncClient,
debug = True,
debug_prefix = "NSE (CECal) | ",
debug_only_errors = True
):
# Pass on the initialization to the parent:
super().__init__(
base_url = r"https://www.nseindia.com/companies-listing/corporate-filings-event-calendar",
data_url = r"https://www.nseindia.com/api/event-calendar",
http_client = http_client,
debug = debug,
debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors
)
async def get_data(
self,
return_raw: bool = False,
) -> NSEApiResponse:
"""
To get the data of the corporate event calendar.
:param return_raw: Whether you want the raw JSON from NSE or you want it formatted.
:return: The raw or formatted event calendar data in the 'data' field of the response model.
"""
# Make the API call:
api_response = await self.get()
# If the API call was successful:
if api_response.httpCode in [200]:
api_response.success = True
if return_raw: api_response.data = await api_response.get_json()
else:
try: api_response.data = self.format_data(
raw_json = await api_response.get_json(),
timestamp = date_time.get_current_utc_date_time(as_string = True),
raise_exception = True
)
except Exception as exception:
api_response.exception = exception
api_response.success = False
# Done here:
return api_response
@staticmethod
def format_data(
raw_json: List[dict],
timestamp: datetime.datetime = None,
raise_exception: bool = False
) -> List[dict] | None:
"""
We format the data here to be able to retrieve it properly later.
:param raw_json: The raw data as scraped from NSE.
:param timestamp: The timestamp at which the data was scraped. This shall be useful for data retrieval from the
database, later.
:param raise_exception: If set to True, any exception will be propagated. If set to False, any exception will be
suppressed internally.
:return: The formatted data if successful, else None.
"""
# Can't do anything if the chain itself is null:
if raw_json is None: return raw_json
# Start by assuming failure:
formatted_data = None
# Ensure that we've got a proper timestamp:
if timestamp is None: timestamp = date_time.get_current_utc_date_time(as_string=False)
try:
# Format the data:
formatted_data = [
{
"ts": timestamp,
"symbol": event["symbol"],
"company": event["company"],
"eventDate": date_time.to_timezone(
date_time.parse_date_time(
event["date"],
timezone = date_time.TIMEZONE_IST
),
timezone = date_time.TIMEZONE_UTC
),
"eventType": event["purpose"],
"brief": event["bm_desc"]
} for event in raw_json
]
# If something goes wrong:
except Exception as exception:
formatted_data = None
if raise_exception: raise
# Done here:
return formatted_data
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
async def main():
# Create an HTTP client:
test_client = httpx.AsyncClient(
limits = httpx.Limits(
max_connections = 100, # ............ Maximum number of connections allowed in the pool.
max_keepalive_connections = 50, # ... Maximum number of connections that can be kept alive.
),
timeout = httpx.Timeout(
connect = 2.5, # ... Shorter connection timeout.
read = 2.5, # ...... Like what EasyEcom gives.
write = 10.0, # .... Time to wait for sending data.
pool = 120.0 # ..... Time to wait for a free connection from the pool.
)
)
# Create an instance of the scraper, and refresh its cookies:
my_nse = NSECorporateEventCalendar(http_client = test_client)
# Get and show the data:
api_response = await my_nse.get_data(return_raw = False)
print("SUMMARY:", api_response.to_markdown(), "\n---\n\n")
if api_response.success: print("CORPORATE EVENT CALENDAR:", json.to_string(api_response.data, default = str))
asyncio.run(main())
@@ -0,0 +1,178 @@
[
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "AAREYDRUGS",
"company": "Aarey Drugs & Pharmaceuticals Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Fund Raising/Other business matters",
"brief": "To consider Fund Raising and other business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "ASTERDM",
"company": "Aster DM Healthcare Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider other business matters pertaining to Preferential Issue."
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "EROSMEDIA",
"company": "Eros International Media Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Financial Results/Other business matters",
"brief": "To consider and approve the financial results for the quarter and year ended March 31, 2024 and other business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "MUFIN",
"company": "Mufin Green Finance Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Fund Raising",
"brief": "To consider Fund Raising by Issue of Secured Unlisted Non Convertible Debenture."
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "ONMOBILE",
"company": "OnMobile Global Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Fund Raising",
"brief": "To consider Fund Raising"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "PRIVISCL",
"company": "Privi Speciality Chemicals Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider and Approve \"Privi Employee Stock Option Scheme - 2024\""
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "SOUTHBANK",
"company": "The South Indian Bank Limited",
"eventDate": "2024-11-28 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider, decide on exercise of call option of Bank s Non-convertible, fully paid-up, unsecured, perpetual, Basel III Compliant, Tier I Bonds, listed in BSE"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "BCG",
"company": "Brightcom Group Limited",
"eventDate": "2024-11-29 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider other business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "BCG",
"company": "Brightcom Group Limited",
"eventDate": "2024-11-29 18:07:00+00:00",
"eventType": "Financial Results",
"brief": "To consider and approve the financial results for the period ended Jun 30, 2024"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "SIKKO",
"company": "Sikko Industries Limited",
"eventDate": "2024-11-29 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider discuss and decide terms and conditions such as determination of the rights issue price, rights entitlement ratio, record date and other matters incidental orconnected therewith."
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "AGIIL",
"company": "Agi Infra Limited",
"eventDate": "2024-12-01 18:07:00+00:00",
"eventType": "Stock Split",
"brief": "To consider stock split of equity shares of the Company"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "MANAKCOAT",
"company": "Manaksia Coated Metals & Industries Limited",
"eventDate": "2024-12-01 18:07:00+00:00",
"eventType": "Fund Raising",
"brief": "To consider Fund Raising"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "NTL",
"company": "Neueon Towers Limited",
"eventDate": "2024-12-01 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider the enclosed business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "PAR",
"company": "Par Drugs and Chemicals Limited",
"eventDate": "2024-12-01 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider other business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "FIBERWEB",
"company": "Fiberweb (India) Limited",
"eventDate": "2024-12-02 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider and discuss about the expansion plans"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "IITL",
"company": "Industrial Investment Trust Limited",
"eventDate": "2024-12-02 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider other business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "SWIGGY",
"company": "Swiggy Limited",
"eventDate": "2024-12-02 18:07:00+00:00",
"eventType": "Financial Results",
"brief": "To consider and approve the financial results for the quarter and half year ended September 30, 2024"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "GBGLOBAL",
"company": "GB Global Limited",
"eventDate": "2024-12-03 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider other business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "MOTOGENFIN",
"company": "The Motor & General Finance Limited",
"eventDate": "2024-12-03 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "Intimation Regarding Independent Directors Meeting will be held on 04.12.2024."
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "DIL",
"company": "Debock Industries Limited",
"eventDate": "2024-12-04 18:07:00+00:00",
"eventType": "Financial Results",
"brief": "DIL : 05-Dec-2024 : The Company has informed the Exchange that a Board meeting to be held on November 27, 2024 has been re-scheduled. Further, the Company has informed the Exchange that the meeting of the Board of Directors of the Company will be held on December 05, 2024, To consider and approve the financial results for the period ended September 30, 2024"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "NTL",
"company": "Neueon Towers Limited",
"eventDate": "2024-12-08 18:07:00+00:00",
"eventType": "Other business matters",
"brief": "To consider enclosed business matters"
},
{
"ts": "2024-11-28 15:11:22.793824+05:30",
"symbol": "EXIDEIND",
"company": "Exide Industries Limited",
"eventDate": "2025-01-27 18:07:00+00:00",
"eventType": "Financial Results",
"brief": "To consider and approve the financial results for the period ended December 31, 2024"
}
]
@@ -0,0 +1,156 @@
[
{
"symbol": "AAREYDRUGS",
"company": "Aarey Drugs & Pharmaceuticals Limited",
"purpose": "Fund Raising/Other business matters",
"bm_desc": "To consider Fund Raising and other business matters",
"date": "29-Nov-2024"
},
{
"symbol": "ASTERDM",
"company": "Aster DM Healthcare Limited",
"purpose": "Other business matters",
"bm_desc": "To consider other business matters pertaining to Preferential Issue.",
"date": "29-Nov-2024"
},
{
"symbol": "EROSMEDIA",
"company": "Eros International Media Limited",
"purpose": "Financial Results/Other business matters",
"bm_desc": "To consider and approve the financial results for the quarter and year ended March 31, 2024 and other business matters",
"date": "29-Nov-2024"
},
{
"symbol": "MUFIN",
"company": "Mufin Green Finance Limited",
"purpose": "Fund Raising",
"bm_desc": "To consider Fund Raising by Issue of Secured Unlisted Non Convertible Debenture.",
"date": "29-Nov-2024"
},
{
"symbol": "ONMOBILE",
"company": "OnMobile Global Limited",
"purpose": "Fund Raising",
"bm_desc": "To consider Fund Raising",
"date": "29-Nov-2024"
},
{
"symbol": "PRIVISCL",
"company": "Privi Speciality Chemicals Limited",
"purpose": "Other business matters",
"bm_desc": "To consider and Approve \"Privi Employee Stock Option Scheme - 2024\"",
"date": "29-Nov-2024"
},
{
"symbol": "SOUTHBANK",
"company": "The South Indian Bank Limited",
"purpose": "Other business matters",
"bm_desc": "To consider, decide on exercise of call option of Bank s Non-convertible, fully paid-up, unsecured, perpetual, Basel III Compliant, Tier I Bonds, listed in BSE",
"date": "29-Nov-2024"
},
{
"symbol": "BCG",
"company": "Brightcom Group Limited",
"purpose": "Other business matters",
"bm_desc": "To consider other business matters",
"date": "30-Nov-2024"
},
{
"symbol": "BCG",
"company": "Brightcom Group Limited",
"purpose": "Financial Results",
"bm_desc": "To consider and approve the financial results for the period ended Jun 30, 2024",
"date": "30-Nov-2024"
},
{
"symbol": "SIKKO",
"company": "Sikko Industries Limited",
"purpose": "Other business matters",
"bm_desc": "To consider discuss and decide terms and conditions such as determination of the rights issue price, rights entitlement ratio, record date and other matters incidental orconnected therewith.",
"date": "30-Nov-2024"
},
{
"symbol": "AGIIL",
"company": "Agi Infra Limited",
"purpose": "Stock Split",
"bm_desc": "To consider stock split of equity shares of the Company",
"date": "02-Dec-2024"
},
{
"symbol": "MANAKCOAT",
"company": "Manaksia Coated Metals & Industries Limited",
"purpose": "Fund Raising",
"bm_desc": "To consider Fund Raising",
"date": "02-Dec-2024"
},
{
"symbol": "NTL",
"company": "Neueon Towers Limited",
"purpose": "Other business matters",
"bm_desc": "To consider the enclosed business matters",
"date": "02-Dec-2024"
},
{
"symbol": "PAR",
"company": "Par Drugs and Chemicals Limited",
"purpose": "Other business matters",
"bm_desc": "To consider other business matters",
"date": "02-Dec-2024"
},
{
"symbol": "FIBERWEB",
"company": "Fiberweb (India) Limited",
"purpose": "Other business matters",
"bm_desc": "To consider and discuss about the expansion plans",
"date": "03-Dec-2024"
},
{
"symbol": "IITL",
"company": "Industrial Investment Trust Limited",
"purpose": "Other business matters",
"bm_desc": "To consider other business matters",
"date": "03-Dec-2024"
},
{
"symbol": "SWIGGY",
"company": "Swiggy Limited",
"purpose": "Financial Results",
"bm_desc": "To consider and approve the financial results for the quarter and half year ended September 30, 2024",
"date": "03-Dec-2024"
},
{
"symbol": "GBGLOBAL",
"company": "GB Global Limited",
"purpose": "Other business matters",
"bm_desc": "To consider other business matters",
"date": "04-Dec-2024"
},
{
"symbol": "MOTOGENFIN",
"company": "The Motor & General Finance Limited",
"purpose": "Other business matters",
"bm_desc": "Intimation Regarding Independent Directors Meeting will be held on 04.12.2024.",
"date": "04-Dec-2024"
},
{
"symbol": "DIL",
"company": "Debock Industries Limited",
"purpose": "Financial Results",
"bm_desc": "DIL : 05-Dec-2024 : The Company has informed the Exchange that a Board meeting to be held on November 27, 2024 has been re-scheduled. Further, the Company has informed the Exchange that the meeting of the Board of Directors of the Company will be held on December 05, 2024, To consider and approve the financial results for the period ended September 30, 2024",
"date": "05-Dec-2024"
},
{
"symbol": "NTL",
"company": "Neueon Towers Limited",
"purpose": "Other business matters",
"bm_desc": "To consider enclosed business matters",
"date": "09-Dec-2024"
},
{
"symbol": "EXIDEIND",
"company": "Exide Industries Limited",
"purpose": "Financial Results",
"bm_desc": "To consider and approve the financial results for the period ended December 31, 2024",
"date": "28-Jan-2025"
}
]