File size: 3,856 Bytes
ed0ae29
7c1d9d6
4a04ebe
 
660a1d2
4a04ebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660a1d2
4a04ebe
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

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 = """
    <html>
    <body>
    <table border="1" style="border-collapse: collapse;">
      <tr>
        <th style="border: 1px solid black;">Application Number</th>
        <th style="border: 1px solid black;">Decision</th>
      </tr>
      <tr>
        <td style="border: 1px solid black;">{}</td>
        <td style="border: 1px solid black;">{}</td>
      </tr>
    </table>
    </body>
    </html>
    """.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 = """
      <html>
      <body>
      <h3>Application number not found. Showing nearest records:</h3>
      <table border="1" style="border-collapse: collapse;">
        <tr>
          <th style="border: 1px solid black;">Application Number</th>
          <th style="border: 1px solid black;">Decision</th>
          <th style="border: 1px solid black;">Difference</th>
        </tr>
      """
      for _, row in nearest_records.iterrows():
          html_table += """
          <tr>
            <td style="border: 1px solid black;">{}</td>
            <td style="border: 1px solid black;">{}</td>
            <td style="border: 1px solid black;">{}</td>
          </tr>
          """.format(row['Application Number'], row['Decision'], row['Difference'])

      html_table += """
      </table>
      </body>
      </html>
      """
      # 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()