Update app.py
#1
by
SR05
- opened
app.py
CHANGED
@@ -1,49 +1,113 @@
|
|
1 |
-
import os
|
2 |
-
import requests
|
3 |
-
from bs4 import BeautifulSoup
|
4 |
-
from datetime import datetime, timedelta
|
5 |
-
import streamlit as st
|
6 |
-
import pandas as pd
|
7 |
-
import pytz
|
8 |
-
#import pyexcel_ods3
|
9 |
-
import requests
|
10 |
|
11 |
import requests
|
|
|
|
|
12 |
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
# Headers to mimic a browser request
|
18 |
-
headers = {
|
19 |
-
"User-Agent": (
|
20 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
21 |
-
"(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
|
22 |
-
)
|
23 |
-
}
|
24 |
-
|
25 |
-
# Send an HTTP GET request to the website with headers
|
26 |
-
response = requests.get(url, headers=headers)
|
27 |
-
|
28 |
-
# Check if the request was successful (status code 200)
|
29 |
-
if response.status_code == 200:
|
30 |
-
# Parse the HTML content of the page
|
31 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
32 |
-
|
33 |
-
# Extract relevant data (e.g., tables, headings, paragraphs)
|
34 |
-
paragraphs = soup.find_all('p')
|
35 |
-
for i, paragraph in enumerate(paragraphs, start=1):
|
36 |
-
print(f"Paragraph {i}: {paragraph.get_text(strip=True)}")
|
37 |
-
print("-" * 80)
|
38 |
-
|
39 |
-
# Example: Scraping tables (if there are any)
|
40 |
-
tables = soup.find_all('table')
|
41 |
-
for table in tables:
|
42 |
-
print("\nTable found:")
|
43 |
-
rows = table.find_all('tr')
|
44 |
-
for row in rows:
|
45 |
-
cells = row.find_all(['th', 'td'])
|
46 |
-
cell_data = [cell.get_text(strip=True) for cell in cells]
|
47 |
-
print("\t".join(cell_data))
|
48 |
-
else:
|
49 |
-
print(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
import requests
|
3 |
+
import pandas as pd
|
4 |
+
from io import BytesIO
|
5 |
from bs4 import BeautifulSoup
|
6 |
+
from IPython.display import HTML, display
|
7 |
+
from IPython.display import clear_output
|
8 |
+
|
9 |
+
|
10 |
+
# ... (Your existing code for fetching and processing the data remains the same) ...
|
11 |
+
|
12 |
+
# ... (Code for reading .ods file, cleaning data, and creating the df DataFrame) ...
|
13 |
+
|
14 |
+
|
15 |
+
def display_application_decision():
|
16 |
+
"""Displays the application decision in an HTML table based on user input."""
|
17 |
+
|
18 |
+
while True:
|
19 |
+
application_number_input = input("Enter your Application Number (including IRL if applicable): ")
|
20 |
+
if "irl" in application_number_input.lower():
|
21 |
+
try:
|
22 |
+
application_number = int("".join(filter(str.isdigit, application_number_input.lower().split("irl")[-1])))
|
23 |
+
if len(str(application_number)) < 8:
|
24 |
+
print("Please enter a valid application number with minimum 8 digits after IRL.")
|
25 |
+
continue
|
26 |
+
break
|
27 |
+
except ValueError:
|
28 |
+
print("Invalid input after IRL. Please enter only digits.")
|
29 |
+
continue
|
30 |
+
|
31 |
+
else:
|
32 |
+
if not application_number_input.isdigit():
|
33 |
+
print("Invalid input. Please enter only digits.")
|
34 |
+
continue
|
35 |
+
elif len(application_number_input) < 8:
|
36 |
+
print("Please enter at least 8 digits for your VISA application number.")
|
37 |
+
continue
|
38 |
+
else:
|
39 |
+
application_number = int(application_number_input)
|
40 |
+
break
|
41 |
+
|
42 |
+
# Find the row corresponding to the entered application number.
|
43 |
+
row = df[df['Application Number'] == application_number]
|
44 |
+
|
45 |
+
if not row.empty:
|
46 |
+
# Congratulate the user if the application is approved
|
47 |
+
if row['Decision'].iloc[0] == 'Approved':
|
48 |
+
print("Congratulations! Your Visa application has been approved.")
|
49 |
+
|
50 |
+
# Create HTML table string
|
51 |
+
html_table = """
|
52 |
+
<html>
|
53 |
+
<body>
|
54 |
+
<table border="1" style="border-collapse: collapse;">
|
55 |
+
<tr>
|
56 |
+
<th style="border: 1px solid black;">Application Number</th>
|
57 |
+
<th style="border: 1px solid black;">Decision</th>
|
58 |
+
</tr>
|
59 |
+
<tr>
|
60 |
+
<td style="border: 1px solid black;">{}</td>
|
61 |
+
<td style="border: 1px solid black;">{}</td>
|
62 |
+
</tr>
|
63 |
+
</table>
|
64 |
+
</body>
|
65 |
+
</html>
|
66 |
+
""".format(row['Application Number'].iloc[0], row['Decision'].iloc[0])
|
67 |
+
|
68 |
+
# Display the HTML table
|
69 |
+
clear_output(wait=True)
|
70 |
+
display(HTML(html_table))
|
71 |
+
else:
|
72 |
+
print("Application number", application_number, "not found in the data.")
|
73 |
+
|
74 |
+
# Find the nearest records if the exact application number is not found
|
75 |
+
df['Difference'] = abs(df['Application Number'] - application_number)
|
76 |
+
nearest_records = df.nsmallest(2, 'Difference')
|
77 |
+
|
78 |
+
if not nearest_records.empty:
|
79 |
+
# Create HTML table string for nearest records
|
80 |
+
html_table = """
|
81 |
+
<html>
|
82 |
+
<body>
|
83 |
+
<h3>Application number not found. Showing nearest records:</h3>
|
84 |
+
<table border="1" style="border-collapse: collapse;">
|
85 |
+
<tr>
|
86 |
+
<th style="border: 1px solid black;">Application Number</th>
|
87 |
+
<th style="border: 1px solid black;">Decision</th>
|
88 |
+
<th style="border: 1px solid black;">Difference</th>
|
89 |
+
</tr>
|
90 |
+
"""
|
91 |
+
for _, row in nearest_records.iterrows():
|
92 |
+
html_table += """
|
93 |
+
<tr>
|
94 |
+
<td style="border: 1px solid black;">{}</td>
|
95 |
+
<td style="border: 1px solid black;">{}</td>
|
96 |
+
<td style="border: 1px solid black;">{}</td>
|
97 |
+
</tr>
|
98 |
+
""".format(row['Application Number'], row['Decision'], row['Difference'])
|
99 |
+
|
100 |
+
html_table += """
|
101 |
+
</table>
|
102 |
+
</body>
|
103 |
+
</html>
|
104 |
+
"""
|
105 |
+
# Display the HTML table
|
106 |
+
clear_output(wait=True)
|
107 |
+
display(HTML(html_table))
|
108 |
+
else:
|
109 |
+
print("Application number not found, and no nearest records found in the data.")
|
110 |
+
|
111 |
|
112 |
+
# Call the function to start the process
|
113 |
+
display_application_decision()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|