CoderHassan commited on
Commit
4f0c982
·
verified ·
1 Parent(s): 8b76fae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -60
app.py CHANGED
@@ -1,9 +1,5 @@
1
- # app.py
2
- import os
3
  import streamlit as st
4
- from scraper import fetch_tariff_from_url
5
  import requests
6
- import plotly.graph_objects as go
7
 
8
  # Define the CITIES dictionary
9
  CITIES = {
@@ -22,7 +18,7 @@ city = st.selectbox("Select the Nearest City", options=list(CITIES.keys()))
22
  # Display the selected city and corresponding company
23
  st.write(f"You selected: {city}, served by: {CITIES[city]}")
24
 
25
- # Replace the URL with the selected city's company URL
26
  url_dict = {
27
  "IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
28
  "FESCO": "https://fesco.com.pk/tariff",
@@ -37,59 +33,13 @@ url_dict = {
37
  selected_url = url_dict[CITIES[city]]
38
  st.write(f"Fetching data from: {selected_url}")
39
 
40
- # Continue with your scraping or data fetching logic using `selected_url`
 
 
 
 
 
 
 
41
 
42
- APPLIANCE_OPTIONS = { ... } # Your existing appliance list
43
-
44
- # Tariff and Carbon Footprint related functions
45
- def calculate_total_units():
46
- ...
47
-
48
- def get_exchange_rate():
49
- """Fetch the real-time USD to PKR conversion rate."""
50
- try:
51
- response = requests.get("https://open.er-api.com/v6/latest/PKR")
52
- response.raise_for_status()
53
- data = response.json()
54
- if "rates" in data and "USD" in data["rates"]:
55
- return 1 / data["rates"]["USD"]
56
- else:
57
- st.error("Exchange rate data is missing expected fields.")
58
- return 300
59
- except Exception as e:
60
- st.error(f"Error fetching exchange rate: {e}")
61
- return 300
62
-
63
- def get_heating_degree_days(latitude, longitude):
64
- ...
65
-
66
- def calculate_footprint(distance_car, distance_bus, distance_plane, electricity_usage, diet_type, shopping_spent_pkr, city, house_area, exchange_rate):
67
- ...
68
-
69
- # Streamlit App
70
- st.title("PowerCalc: AI-Driven Bill & Carbon Footprint Tracker")
71
-
72
- # Tariff Input and Appliance Section
73
- st.sidebar.subheader("Fetch Tariff Data")
74
- tariff_url = st.sidebar.text_input("Enter URL to scrape tariff data:")
75
- load_type = st.sidebar.selectbox("Select Load Type", ["Residential", "Commercial", "Industrial", "Agriculture"])
76
-
77
- if st.sidebar.button("Fetch Tariff"):
78
- rate = fetch_tariff_from_url(tariff_url, load_type)
79
- if rate:
80
- st.session_state.tariff_rate = rate
81
- st.sidebar.success(f"Tariff fetched for {load_type}: {rate} PKR/unit")
82
- else:
83
- st.sidebar.warning("Failed to fetch tariff rate. Ensure the URL and load type are correct.")
84
-
85
- # Add Appliances Section
86
- ...
87
-
88
- # Calculate Carbon Footprint Section
89
- st.header("Calculate Carbon Footprint")
90
- city = st.selectbox("Select the Nearest City", options=list(CITIES.keys()))
91
- ...
92
- if st.button("Calculate Carbon Footprint"):
93
- result = calculate_footprint(...)
94
- st.subheader(f"Your Estimated Monthly Carbon Footprint: {result['total_emissions']:.2f} kg CO2")
95
- ...
 
 
 
1
  import streamlit as st
 
2
  import requests
 
3
 
4
  # Define the CITIES dictionary
5
  CITIES = {
 
18
  # Display the selected city and corresponding company
19
  st.write(f"You selected: {city}, served by: {CITIES[city]}")
20
 
21
+ # Define the URLs for each company
22
  url_dict = {
23
  "IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
24
  "FESCO": "https://fesco.com.pk/tariff",
 
33
  selected_url = url_dict[CITIES[city]]
34
  st.write(f"Fetching data from: {selected_url}")
35
 
36
+ # Fetch and display the tariff data
37
+ try:
38
+ response = requests.get(selected_url)
39
+ response.raise_for_status()
40
+ st.write("Data fetched successfully!")
41
+ st.write(response.text)
42
+ except requests.RequestException as e:
43
+ st.error(f"An error occurred while fetching data: {e}")
44
 
45
+ # Add any additional logic here for processing and displaying the tariff data