import requests
import pandas as pd
from io import BytesIO
from bs4 import BeautifulSoup
from IPython.display import HTML, display
from IPython.display import clear_output
# ... (Your existing code for fetching and processing the data remains the same) ...
# ... (Code for reading .ods file, cleaning data, and creating the df DataFrame) ...
def display_application_decision():
"""Displays the application decision in an HTML table based on user input."""
while True:
application_number_input = input("Enter your Application Number (including IRL if applicable): ")
if "irl" in application_number_input.lower():
try:
application_number = int("".join(filter(str.isdigit, application_number_input.lower().split("irl")[-1])))
if len(str(application_number)) < 8:
print("Please enter a valid application number with minimum 8 digits after IRL.")
continue
break
except ValueError:
print("Invalid input after IRL. Please enter only digits.")
continue
else:
if not application_number_input.isdigit():
print("Invalid input. Please enter only digits.")
continue
elif len(application_number_input) < 8:
print("Please enter at least 8 digits for your VISA application number.")
continue
else:
application_number = int(application_number_input)
break
# Find the row corresponding to the entered application number.
row = df[df['Application Number'] == application_number]
if not row.empty:
# Congratulate the user if the application is approved
if row['Decision'].iloc[0] == 'Approved':
print("Congratulations! Your Visa application has been approved.")
# Create HTML table string
html_table = """
Application Number |
Decision |
{} |
{} |
""".format(row['Application Number'].iloc[0], row['Decision'].iloc[0])
# Display the HTML table
clear_output(wait=True)
display(HTML(html_table))
else:
print("Application number", application_number, "not found in the data.")
# Find the nearest records if the exact application number is not found
df['Difference'] = abs(df['Application Number'] - application_number)
nearest_records = df.nsmallest(2, 'Difference')
if not nearest_records.empty:
# Create HTML table string for nearest records
html_table = """
Application number not found. Showing nearest records:
Application Number |
Decision |
Difference |
"""
for _, row in nearest_records.iterrows():
html_table += """
{} |
{} |
{} |
""".format(row['Application Number'], row['Decision'], row['Difference'])
html_table += """
"""
# Display the HTML table
clear_output(wait=True)
display(HTML(html_table))
else:
print("Application number not found, and no nearest records found in the data.")
# Call the function to start the process
display_application_decision()