Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,29 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
def main():
|
| 5 |
st.title("PESCO Tariff Rates Viewer")
|
| 6 |
st.write("This app fetches and displays the latest PESCO tariff rates.")
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
if st.button("Fetch PESCO Tariff Rates"):
|
| 10 |
url = TARIFF_URLS["PESCO"]
|
| 11 |
st.write(f"Fetching data from {url}...")
|
| 12 |
|
| 13 |
with st.spinner("Scraping data..."):
|
| 14 |
-
|
| 15 |
-
if
|
| 16 |
-
st.success("Data
|
| 17 |
-
st.write("### Tariff Rates:")
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
else:
|
| 21 |
-
st.error(
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
| 24 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from tariff_scraper import TARIFF_URLS, scrape_tariff_data_to_csv
|
| 4 |
|
| 5 |
def main():
|
| 6 |
st.title("PESCO Tariff Rates Viewer")
|
| 7 |
st.write("This app fetches and displays the latest PESCO tariff rates.")
|
| 8 |
|
| 9 |
+
# Button to fetch and save tariff rates
|
| 10 |
+
if st.button("Fetch and Save PESCO Tariff Rates"):
|
| 11 |
url = TARIFF_URLS["PESCO"]
|
| 12 |
st.write(f"Fetching data from {url}...")
|
| 13 |
|
| 14 |
with st.spinner("Scraping data..."):
|
| 15 |
+
output_file = scrape_tariff_data_to_csv(url)
|
| 16 |
+
if output_file.endswith(".csv"):
|
| 17 |
+
st.success(f"Data successfully saved to {output_file}!")
|
| 18 |
+
st.write("### Preview of Tariff Rates:")
|
| 19 |
+
try:
|
| 20 |
+
# Read the CSV file and display it in tabular format
|
| 21 |
+
data = pd.read_csv(output_file)
|
| 22 |
+
st.dataframe(data)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
st.error(f"Error reading the CSV file: {e}")
|
| 25 |
else:
|
| 26 |
+
st.error(output_file)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
main()
|