File size: 2,337 Bytes
0666a7c
 
 
aa663df
4fe526b
0666a7c
4fe526b
0666a7c
ff0a9d2
0666a7c
4fe526b
0666a7c
4fe526b
 
0666a7c
 
aa663df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4fe526b
aa663df
 
 
0666a7c
 
 
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
import streamlit as st
import requests

# Function to fetch exchange rates for multiple currencies to PKR
def get_exchange_rates_to_pkr():
    try:
        url = "https://api.exchangerate-api.com/v4/latest/PKR"
        response = requests.get(url)
        response.raise_for_status()
        data = response.json()
        return data["rates"]
    except Exception as e:
        st.error(f"Error fetching exchange rates: {e}")
        return {}

def main():
    # App title and icon
    st.set_page_config(page_title="Currency to PKR Converter", page_icon="💰")

    # Background styling
    st.markdown(
        """
        <style>
        body {
            background-color: #f5f5f5;
            font-family: Arial, sans-serif;
        }
        .stApp {
            background-color: #e0f7fa;
            border-radius: 10px;
            padding: 20px;
        }
        </style>
        """,
        unsafe_allow_html=True,
    )

    st.title("💰 Currency to PKR Converter")
    st.write("Convert amounts from multiple currencies to Pakistani Rupees (PKR).")

    # Currencies with country names
    currencies = {
        "USD": "United States Dollar",
        "EUR": "Euro (European Union)",
        "GBP": "British Pound Sterling",
        "AED": "United Arab Emirates Dirham",
        "SAR": "Saudi Riyal",
        "KWD": "Kuwaiti Dinar",
        "TRY": "Turkish Lira",
        "JPY": "Japanese Yen",
        "AUD": "Australian Dollar",
        "CAD": "Canadian Dollar",
        "CNY": "Chinese Yuan",
        "INR": "Indian Rupee",
        "CHF": "Swiss Franc",
        "SEK": "Swedish Krona",
    }

    # Fetch exchange rates
    rates = get_exchange_rates_to_pkr()

    if rates:
        # Input fields for each currency
        for code, name in currencies.items():
            amount = st.number_input(f"Enter the amount in {name} ({code}):", min_value=0.0, format="%.2f")
            if amount > 0:
                if code in rates:
                    converted = amount / rates[code]
                    st.success(f"{amount:.2f} {code} ({name}) = {converted:.2f} PKR")
                else:
                    st.warning(f"Exchange rate for {code} ({name}) is not available.")
    else:
        st.error("Failed to load exchange rates. Please refresh or try again later.")

if __name__ == "__main__":
    main()