Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import socket
|
| 3 |
import requests
|
|
|
|
| 4 |
from urllib.parse import urlparse
|
| 5 |
|
| 6 |
# Function to extract the domain name from the URL
|
|
@@ -32,13 +33,17 @@ def get_country_info(ip):
|
|
| 32 |
|
| 33 |
# Function to get the flag URL from a country code
|
| 34 |
def get_country_flag(country_name):
|
| 35 |
-
|
| 36 |
-
"US"
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Streamlit app
|
| 44 |
def main():
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import socket
|
| 3 |
import requests
|
| 4 |
+
import pycountry
|
| 5 |
from urllib.parse import urlparse
|
| 6 |
|
| 7 |
# Function to extract the domain name from the URL
|
|
|
|
| 33 |
|
| 34 |
# Function to get the flag URL from a country code
|
| 35 |
def get_country_flag(country_name):
|
| 36 |
+
try:
|
| 37 |
+
# Using pycountry to get the alpha_2 country code (e.g., "US", "IN")
|
| 38 |
+
country = pycountry.countries.get(name=country_name)
|
| 39 |
+
if country:
|
| 40 |
+
country_code = country.alpha_2
|
| 41 |
+
flag_url = f"https://countryflagsapi.com/png/{country_code.lower()}"
|
| 42 |
+
return flag_url
|
| 43 |
+
else:
|
| 44 |
+
return "https://countryflagsapi.com/png/unknown" # Default flag if country not found
|
| 45 |
+
except AttributeError:
|
| 46 |
+
return "https://countryflagsapi.com/png/unknown" # Return unknown flag if error
|
| 47 |
|
| 48 |
# Streamlit app
|
| 49 |
def main():
|