Spaces:
Running
Running
Update bhavcopy_html.py
Browse files- bhavcopy_html.py +5 -5
bhavcopy_html.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import nsepython as nse
|
| 3 |
import persist
|
| 4 |
-
from datetime import datetime
|
| 5 |
|
| 6 |
|
| 7 |
def build_bhavcopy_html(date_str):
|
|
@@ -14,7 +14,7 @@ def build_bhavcopy_html(date_str):
|
|
| 14 |
cached = persist.load(key, "html")
|
| 15 |
if cached is not False:
|
| 16 |
print(
|
| 17 |
-
f"[{
|
| 18 |
f"Using cached bhavcopy for {date_str}"
|
| 19 |
)
|
| 20 |
return cached
|
|
@@ -24,14 +24,14 @@ def build_bhavcopy_html(date_str):
|
|
| 24 |
# 1) Validate Date (DD-MM-YYYY)
|
| 25 |
# -------------------------------------------------------
|
| 26 |
try:
|
| 27 |
-
|
| 28 |
except ValueError:
|
| 29 |
html = "<h3>Invalid date format. Use DD-MM-YYYY.</h3>"
|
| 30 |
persist.save(key, html, "html")
|
| 31 |
return html
|
| 32 |
|
| 33 |
# -------------------------------------------------------
|
| 34 |
-
# 2) Fetch Bhavcopy (nsepython
|
| 35 |
# -------------------------------------------------------
|
| 36 |
try:
|
| 37 |
df = nse.nse_bhavcopy(date_str)
|
|
@@ -141,7 +141,7 @@ def build_bhavcopy_html(date_str):
|
|
| 141 |
|
| 142 |
except Exception as e:
|
| 143 |
print(
|
| 144 |
-
f"[{
|
| 145 |
f"Error build_bhavcopy_html: {e}"
|
| 146 |
)
|
| 147 |
return f"<h3>Error: {e}</h3>"
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import nsepython as nse
|
| 3 |
import persist
|
| 4 |
+
from datetime import datetime as dt
|
| 5 |
|
| 6 |
|
| 7 |
def build_bhavcopy_html(date_str):
|
|
|
|
| 14 |
cached = persist.load(key, "html")
|
| 15 |
if cached is not False:
|
| 16 |
print(
|
| 17 |
+
f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] "
|
| 18 |
f"Using cached bhavcopy for {date_str}"
|
| 19 |
)
|
| 20 |
return cached
|
|
|
|
| 24 |
# 1) Validate Date (DD-MM-YYYY)
|
| 25 |
# -------------------------------------------------------
|
| 26 |
try:
|
| 27 |
+
dt.strptime(date_str, "%d-%m-%Y")
|
| 28 |
except ValueError:
|
| 29 |
html = "<h3>Invalid date format. Use DD-MM-YYYY.</h3>"
|
| 30 |
persist.save(key, html, "html")
|
| 31 |
return html
|
| 32 |
|
| 33 |
# -------------------------------------------------------
|
| 34 |
+
# 2) Fetch Bhavcopy (nsepython expects DD-MM-YYYY)
|
| 35 |
# -------------------------------------------------------
|
| 36 |
try:
|
| 37 |
df = nse.nse_bhavcopy(date_str)
|
|
|
|
| 141 |
|
| 142 |
except Exception as e:
|
| 143 |
print(
|
| 144 |
+
f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] "
|
| 145 |
f"Error build_bhavcopy_html: {e}"
|
| 146 |
)
|
| 147 |
return f"<h3>Error: {e}</h3>"
|