Update loading_file.py
Browse files- loading_file.py +52 -3
loading_file.py
CHANGED
@@ -58,7 +58,7 @@ def fetch_data():
|
|
58 |
|
59 |
# Trim unnecessary rows and set correct header
|
60 |
df = df.iloc[header_index:].reset_index(drop=True)
|
61 |
-
df.columns = df.iloc[0]
|
62 |
df = df[1:].reset_index(drop=True) # Remove the header row from data
|
63 |
|
64 |
# Keep only relevant columns
|
@@ -68,10 +68,59 @@ def fetch_data():
|
|
68 |
|
69 |
df = df[["Application Number", "Decision"]]
|
70 |
|
71 |
-
#
|
72 |
-
df["Application Number"] =
|
73 |
|
|
|
|
|
74 |
return df, file_name
|
75 |
|
76 |
# Fetch data once and store it globally
|
77 |
precomputed_df, file_name = fetch_data()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Trim unnecessary rows and set correct header
|
60 |
df = df.iloc[header_index:].reset_index(drop=True)
|
61 |
+
df.columns = df.iloc[0] # Set the first row as column headers
|
62 |
df = df[1:].reset_index(drop=True) # Remove the header row from data
|
63 |
|
64 |
# Keep only relevant columns
|
|
|
68 |
|
69 |
df = df[["Application Number", "Decision"]]
|
70 |
|
71 |
+
# Ensure "Application Number" is treated as a string to match user input correctly
|
72 |
+
df["Application Number"] = df["Application Number"].astype(str).str.strip()
|
73 |
|
74 |
+
print("Data fetched successfully.")
|
75 |
+
|
76 |
return df, file_name
|
77 |
|
78 |
# Fetch data once and store it globally
|
79 |
precomputed_df, file_name = fetch_data()
|
80 |
+
|
81 |
+
# Function to determine before/after status
|
82 |
+
def check_application_status(application_number):
|
83 |
+
if precomputed_df is None:
|
84 |
+
return "Error fetching data"
|
85 |
+
|
86 |
+
application_number = str(application_number).strip() # Ensure it's a string
|
87 |
+
|
88 |
+
min_app_number = precomputed_df["Application Number"].min()
|
89 |
+
max_app_number = precomputed_df["Application Number"].max()
|
90 |
+
|
91 |
+
if application_number in precomputed_df["Application Number"].values:
|
92 |
+
decision = precomputed_df.loc[precomputed_df["Application Number"] == application_number, "Decision"].values[0]
|
93 |
+
return f"Decision: {decision}"
|
94 |
+
elif application_number < min_app_number:
|
95 |
+
return f"Application number {application_number} is from the past. Decision might not be recorded."
|
96 |
+
elif application_number > max_app_number:
|
97 |
+
return f"Application number {application_number} is in the future. Decision is pending."
|
98 |
+
else:
|
99 |
+
return "No data found."
|
100 |
+
|
101 |
+
# Function to generate a PDF
|
102 |
+
def generate_pdf(df, title="Visa Decisions"):
|
103 |
+
pdf = FPDF()
|
104 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
105 |
+
pdf.add_page()
|
106 |
+
pdf.set_font("Arial", size=12)
|
107 |
+
|
108 |
+
pdf.cell(200, 10, txt=title, ln=True, align="C")
|
109 |
+
pdf.ln(10)
|
110 |
+
|
111 |
+
for index, row in df.iterrows():
|
112 |
+
pdf.cell(50, 10, txt="Application Number:", ln=False)
|
113 |
+
pdf.cell(100, 10, txt=str(row["Application Number"]), ln=True)
|
114 |
+
|
115 |
+
pdf.cell(50, 10, txt="Decision:", ln=False)
|
116 |
+
pdf.cell(100, 10, txt=str(row["Decision"]), ln=True)
|
117 |
+
|
118 |
+
pdf.ln(5)
|
119 |
+
|
120 |
+
pdf_output = BytesIO()
|
121 |
+
pdf.output(pdf_output, "F")
|
122 |
+
pdf_output.seek(0)
|
123 |
+
|
124 |
+
return pdf_output
|
125 |
+
|
126 |
+
print("Loading File Module: generate_pdf is defined.")
|