|
import streamlit as st |
|
import requests |
|
import pandas as pd |
|
|
|
|
|
def jina(url): |
|
base_url = "https://r.jina.ai/" |
|
url = base_url + url |
|
response = requests.get(url) |
|
return response.text |
|
|
|
def price_cities(url): |
|
text = jina(url) |
|
pos1 = text.find('**') |
|
new = text[:pos1] |
|
|
|
twentytwok = new[int(new.find('22K')):int(new.find('24K'))] |
|
value_22k = twentytwok[int(twentytwok.find('\n\n') + 1): int(twentytwok.find('\n\n+'))][3:] |
|
value_22k = value_22k.split('\n')[0] |
|
|
|
twentyfourk = new[int(new.find('24K')):int(new.find('18K'))] |
|
value_24k = twentyfourk[int(twentyfourk.find('\n\n') + 1): int(twentyfourk.find('\n\n+'))][3:] |
|
value_24k = value_24k.split('\n')[0] |
|
|
|
eighteenk = new[int(new.find('18K')):] |
|
value_18k = eighteenk[int(eighteenk.find('\n\n') + 1): int(eighteenk.find('\n\n+'))][3:] |
|
value_18k = value_18k.split('\n')[0] |
|
|
|
return value_24k, value_22k, value_18k |
|
|
|
cities = ['Ahmedabad', 'Ayodhya', 'Bangalore', 'Bhubaneswar', 'Chandigarh', 'Chennai', |
|
'Coimbatore', 'Delhi', 'Hyderabad', 'Jaipur', 'Kerala', 'Kolkata', 'Lucknow', |
|
'Madurai', 'Mangalore', 'Mumbai', 'Mysore', 'Nagpur', 'Nashik', 'Patna', |
|
'Pune', 'Rajkot', 'Salem', 'Surat', 'Trichy', 'Vadodara', 'Vijayawada', 'Visakhapatnam'] |
|
|
|
|
|
st.sidebar.title("About the Project") |
|
st.sidebar.write("This project fetches current gold rates for 24K, 22K, and 18K gold from GoodReturns for 28 Indian states. The rates for 1g, 8g, and 10g are displayed.") |
|
st.sidebar.write("**Developed by:**") |
|
st.sidebar.write("[Srish Rachamalla](https://www.linkedin.com/in/srishrachamalla/)") |
|
st.sidebar.write("[Sai Teja Pallerla](https://www.linkedin.com/in/saiteja-pallerla-668734225/)") |
|
|
|
|
|
st.title('Gold Rates in Indian Cities') |
|
st.subheader('Select a city to view the current gold rates') |
|
|
|
|
|
selected_city = st.selectbox('Select a City', cities) |
|
|
|
|
|
if selected_city: |
|
city_url = f"https://www.goodreturns.in/gold-rates/{selected_city}.html" |
|
|
|
|
|
try: |
|
value_24k, value_22k, value_18k = price_cities(city_url) |
|
|
|
|
|
value_22k = round(float(value_22k.replace(',', '')),2) |
|
value_24k = round(float(value_24k.replace(',', '')),2) |
|
value_18k = round(float(value_18k.replace(',', '')),2) |
|
|
|
data = { |
|
|
|
'Gold Purity': ['24K', '22K', '18K'], |
|
'1g Price (₹)': [value_24k, value_22k, value_18k], |
|
'8g Price (₹)': [value_24k * 8, value_22k * 8, value_18k * 8], |
|
'10g Price (₹)': [value_24k * 10, value_22k * 10, value_18k * 10] |
|
} |
|
|
|
|
|
df = pd.DataFrame(data,index=[1, 2, 3]) |
|
|
|
|
|
st.write(f"Gold rates in {selected_city}:") |
|
st.dataframe(df.style.format(precision=2).set_properties(**{ |
|
'background-color': 'black', |
|
'color': 'white', |
|
'border-color': 'ash' |
|
})) |
|
|
|
|
|
except Exception as e: |
|
st.error(f"Could not fetch the gold rates. Please try again.{e}") |
|
|
|
st.markdown("<br><hr><center><p style='color: grey;'>© 2024 All Rights Reserved</p></center><br>", unsafe_allow_html=True) |
|
|
|
|
|
|