Engineer786 commited on
Commit
c654bd8
·
verified ·
1 Parent(s): 039e026

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,24 +1,29 @@
1
  import streamlit as st
2
- from tariff_scraper import TARIFF_URLS, scrape_tariff_data
 
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
- # Display the fetch button
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
- data = scrape_tariff_data(url)
15
- if data and isinstance(data, list) and len(data) > 0:
16
- st.success("Data fetched successfully!")
17
- st.write("### Tariff Rates:")
18
- for row in data:
19
- st.write(row)
 
 
 
 
20
  else:
21
- st.error("Failed to fetch tariff data or no data found.")
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()