|
import streamlit as st |
|
import requests |
|
from datetime import datetime |
|
|
|
|
|
def fetch_exchange_rates(base_currency="PKR"): |
|
url = f"https://v6.exchangerate-api.com/v6/YOUR_API_KEY/latest/{base_currency}" |
|
response = requests.get(url) |
|
data = response.json() |
|
if response.status_code == 200: |
|
return data['conversion_rates'] |
|
else: |
|
st.error("Error fetching data. Please try again later.") |
|
return {} |
|
|
|
|
|
def convert_currency(amount, from_currency, to_currency, rates): |
|
if from_currency == to_currency: |
|
return amount |
|
amount_in_base_currency = amount / rates[from_currency] |
|
converted_amount = amount_in_base_currency * rates[to_currency] |
|
return converted_amount |
|
|
|
|
|
st.set_page_config(page_title="PKR Currency Converter", page_icon="💰", layout="wide") |
|
|
|
|
|
now = datetime.now() |
|
current_date = now.strftime("%Y-%m-%d") |
|
st.sidebar.markdown(f"### Current Date: {current_date}") |
|
|
|
|
|
st.sidebar.title("PKR Currency Converter") |
|
|
|
|
|
st.sidebar.markdown(""" |
|
This app allows you to convert **Pakistani Rupees (PKR)** to any other currency. |
|
Simply enter the amount in PKR, select the target currency, and click 'Convert'. |
|
""") |
|
|
|
|
|
currency_list = ['USD', 'EUR', 'GBP', 'INR', 'AUD', 'CAD', 'JPY', 'CNY', 'CHF', 'MXN', 'ZAR', 'RUB', 'BRL', 'NZD'] |
|
|
|
|
|
st.title("PKR Currency Conversion App") |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.reportview-container { |
|
background-color: #f0f8ff; /* Light background */ |
|
} |
|
.sidebar .sidebar-content { |
|
background-color: #f0f8ff; /* Sidebar background color */ |
|
} |
|
.stButton>button { |
|
background-color: #4CAF50; |
|
color: white; |
|
font-size: 16px; |
|
border-radius: 5px; |
|
padding: 10px; |
|
border: none; |
|
} |
|
.stButton>button:hover { |
|
background-color: #45a049; |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
amount = st.number_input("Enter amount in Pakistani Rupees (PKR)", min_value=0.0, format="%.2f", value=0.0) |
|
|
|
|
|
to_currency = st.selectbox("Convert to", currency_list) |
|
|
|
|
|
rates = fetch_exchange_rates("PKR") |
|
|
|
|
|
if st.button("Convert"): |
|
if amount > 0: |
|
converted_amount = convert_currency(amount, "PKR", to_currency, rates) |
|
st.success(f"{amount} PKR = {converted_amount:.2f} {to_currency}") |
|
else: |
|
st.warning("Please enter a valid amount in PKR.") |
|
|
|
|
|
st.markdown(""" |
|
--- |
|
<p style="font-size:14px; text-align:center;">Made with ❤️ using Streamlit</p> |
|
""", unsafe_allow_html=True) |
|
|