File size: 2,925 Bytes
ca6e954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st
import requests
from datetime import datetime

# Fetch live exchange rates from an API (ExchangeRate-API)
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 {}

# Function to convert currencies
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

# Set page config
st.set_page_config(page_title="PKR Currency Converter", page_icon="💰", layout="wide")

# Sidebar - Display current date
now = datetime.now()
current_date = now.strftime("%Y-%m-%d")
st.sidebar.markdown(f"### Current Date: {current_date}")

# Sidebar - Title
st.sidebar.title("PKR Currency Converter")

# Sidebar - Description
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'.
""")

# Sidebar - Currency list (converting from PKR to other popular currencies)
currency_list = ['USD', 'EUR', 'GBP', 'INR', 'AUD', 'CAD', 'JPY', 'CNY', 'CHF', 'MXN', 'ZAR', 'RUB', 'BRL', 'NZD']

# Main title
st.title("PKR Currency Conversion App")

# Set a light background color for the main 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)

# Input: Amount to convert
amount = st.number_input("Enter amount in Pakistani Rupees (PKR)", min_value=0.0, format="%.2f", value=0.0)

# Select target currency
to_currency = st.selectbox("Convert to", currency_list)

# Fetch exchange rates for PKR
rates = fetch_exchange_rates("PKR")

# Show conversion button and output
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.")

# Footer (optional)
st.markdown("""
    --- 
    <p style="font-size:14px; text-align:center;">Made with ❤️ using Streamlit</p>
    """, unsafe_allow_html=True)