Upload Untitled3.py
Browse files- Untitled3.py +108 -0
Untitled3.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[10]:
|
5 |
+
|
6 |
+
|
7 |
+
import requests
|
8 |
+
import pandas as pd
|
9 |
+
from io import BytesIO
|
10 |
+
from bs4 import BeautifulSoup
|
11 |
+
|
12 |
+
# URL of the website to scrape
|
13 |
+
url = "https://www.ireland.ie/en/india/newdelhi/services/visas/processing-times-and-decisions/"
|
14 |
+
|
15 |
+
# Headers to mimic a browser request
|
16 |
+
headers = {
|
17 |
+
"User-Agent": (
|
18 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
19 |
+
"(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
|
20 |
+
)
|
21 |
+
}
|
22 |
+
|
23 |
+
# Send an HTTP GET request to the website
|
24 |
+
response = requests.get(url, headers=headers)
|
25 |
+
|
26 |
+
# Check if the request was successful
|
27 |
+
if response.status_code == 200:
|
28 |
+
# Parse the HTML content of the page
|
29 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
30 |
+
|
31 |
+
# Find all anchor tags
|
32 |
+
links = soup.find_all('a')
|
33 |
+
|
34 |
+
# Search for the link that contains the specific text
|
35 |
+
file_url = None
|
36 |
+
for link in links:
|
37 |
+
link_text = link.get_text(strip=True)
|
38 |
+
if "Visa decisions made from 1 January 2024 to" in link_text:
|
39 |
+
file_url = link.get('href')
|
40 |
+
break
|
41 |
+
|
42 |
+
# Check if the link was found
|
43 |
+
if file_url:
|
44 |
+
# Make the link absolute if it is relative
|
45 |
+
if not file_url.startswith('http'):
|
46 |
+
file_url = requests.compat.urljoin(url, file_url)
|
47 |
+
|
48 |
+
print(f"Found link: {file_url}")
|
49 |
+
|
50 |
+
# Download the file into memory
|
51 |
+
file_response = requests.get(file_url, headers=headers)
|
52 |
+
|
53 |
+
if file_response.status_code == 200:
|
54 |
+
# Load the file into a BytesIO object
|
55 |
+
ods_file = BytesIO(file_response.content)
|
56 |
+
|
57 |
+
# Read the .ods file using pandas
|
58 |
+
try:
|
59 |
+
# Load the .ods file into a DataFrame
|
60 |
+
df = pd.read_excel(ods_file, engine='odf')
|
61 |
+
|
62 |
+
# Step 1: Clean the DataFrame
|
63 |
+
# Drop the first two columns
|
64 |
+
df.drop(columns=["Unnamed: 0", "Unnamed: 1"], inplace=True)
|
65 |
+
|
66 |
+
# Step 2: Drop NaN rows until we find the actual header row
|
67 |
+
df.dropna(how='all', inplace=True)
|
68 |
+
|
69 |
+
# Step 3: Reset index and rename the header row
|
70 |
+
df.reset_index(drop=True, inplace=True)
|
71 |
+
|
72 |
+
# Step 4: Find the row where "Application Number" starts
|
73 |
+
for idx, row in df.iterrows():
|
74 |
+
if row['Unnamed: 2'] == 'Application Number' and row['Unnamed: 3'] == 'Decision':
|
75 |
+
df.columns = ['Application Number', 'Decision']
|
76 |
+
df = df.iloc[idx + 1:] # Skip the header row
|
77 |
+
break
|
78 |
+
|
79 |
+
# Step 5: Reset the index after cleaning
|
80 |
+
df.reset_index(drop=True, inplace=True)
|
81 |
+
|
82 |
+
# Convert "Application Number" to string for consistency
|
83 |
+
df['Application Number'] = df['Application Number'].astype(str)
|
84 |
+
|
85 |
+
# Display the cleaned DataFrame
|
86 |
+
#print("Cleaned Data:")
|
87 |
+
#print(df.to_string(index=False))
|
88 |
+
|
89 |
+
# Step 6: Ask the user for their application number
|
90 |
+
user_application_number = input("\nEnter your Application Number: ").strip()
|
91 |
+
|
92 |
+
# Step 7: Check if the application number exists in the DataFrame
|
93 |
+
result = df[df['Application Number'] == user_application_number]
|
94 |
+
|
95 |
+
if not result.empty:
|
96 |
+
print(f"\nCongratulations! Your visa application ({user_application_number}) has been {result.iloc[0]['Decision']}.")
|
97 |
+
else:
|
98 |
+
print(f"\nSorry, no record found for Application Number: {user_application_number}.")
|
99 |
+
|
100 |
+
except Exception as e:
|
101 |
+
print("Error reading the .ods file:", e)
|
102 |
+
else:
|
103 |
+
print("Failed to download the file. Status code:", file_response.status_code)
|
104 |
+
else:
|
105 |
+
print("The specified link was not found.")
|
106 |
+
else:
|
107 |
+
print(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
108 |
+
|