(20251122) Reverted formatting and added a semaphore.

This commit is contained in:
2025-11-22 14:57:40 +05:30
parent cbc151570b
commit 071f86e552
4 changed files with 71 additions and 59 deletions
+32 -23
View File
@@ -75,6 +75,7 @@ from cosec_web.cosec_web import CosecWeb
from backend.shared import constants
# To work with dat and time:
import time
import datetime
# For asynchronous activities:
@@ -174,33 +175,41 @@ async def in_out_report_generate(
# Show all the paths for debugging:
current_app.printer("PATHS:", chrome_driver_dir, user_data_dir, downloads_dir)
# Create an instance of the automation object:
cosec = CosecWeb(
cosec_url = inbound_headers.cosecUrl,
username = inbound_headers.cosecUsername,
password = inbound_headers.cosecPassword,
driver_dir = chrome_driver_dir,
user_data_dir = user_data_dir,
downloads_dir = downloads_dir,
)
# Wait for the semaphore so that only one instance is automating Chrome at a time:
async with current_app.chrome_semaphore:
# Perform the login:
cosec.login(initial_sleep = 2.5)
# First kill the previous processes:
kill_count = CosecWeb.kill_chrome_processes()
current_app.printer("Killed Chrome Procs.", kill_count)
if kill_count > 0: time.sleep(2.5)
# Get the in/out report:
report_path = cosec.get_in_out_summary(
initial_sleep = 1.0,
from_date = inbound_data.fromDate,
to_date = inbound_data.toDate,
group_ids = inbound_data.groupIds,
download_timeout = 60.0
)
# Create an instance of the automation object:
cosec = CosecWeb(
cosec_url = inbound_headers.cosecUrl,
username = inbound_headers.cosecUsername,
password = inbound_headers.cosecPassword,
driver_dir = chrome_driver_dir,
user_data_dir = user_data_dir,
downloads_dir = downloads_dir,
)
# Log out to end the cycle:
cosec.logout()
# Perform the login:
cosec.login(initial_sleep = 2.5)
# Close the browser window:
cosec.quit()
# Get the in/out report:
report_path = cosec.get_in_out_summary(
initial_sleep = 1.0,
from_date = inbound_data.fromDate,
to_date = inbound_data.toDate,
group_ids = inbound_data.groupIds,
download_timeout = 60.0
)
# Log out to end the cycle:
cosec.logout()
# Close the browser window:
cosec.quit()
# If we didn't get any path, the download failed:
if report_path is None:
+24 -22
View File
@@ -176,31 +176,33 @@ async def muster_roll_report_generate(
report_data = None
# Get the muster roll data:
report_data = muster_roll.load(
cosec_url = inbound_headers.cosecUrl,
username = inbound_headers.cosecUsername,
password = inbound_headers.cosecPassword,
group_ids = inbound_data.groupIds,
on_date = inbound_data.onDate,
)
async with current_app.chrome_semaphore:
report_data = muster_roll.load(
cosec_url = inbound_headers.cosecUrl,
username = inbound_headers.cosecUsername,
password = inbound_headers.cosecPassword,
group_ids = inbound_data.groupIds,
on_date = inbound_data.onDate,
)
# If data was loaded:
if report_data is not None:
report_data = report_data.copy()
report_data = report_data[[
"User ID", "User Name", "Category Name",
"Grade Name", "Branch Name", "Department Name",
"Direct Reporting", "Level-1"
]]
unique_branches = report_data["Branch Name"].unique().tolist()
unique_depts = report_data[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
unique_reportees = report_data[["Branch Name", "Department Name", "Direct Reporting"]].drop_duplicates().to_dict(orient = "records")
unique_combos = {
"Branch Name": unique_branches,
"Department Name": unique_depts,
"Direct Reporting": unique_reportees
}
report_data = unique_combos
# report_data = report_data.copy()
# report_data = report_data[[
# "User ID", "User Name", "Category Name",
# "Grade Name", "Branch Name", "Department Name",
# "Direct Reporting", "Level-1"
# ]]
# unique_branches = report_data["Branch Name"].unique().tolist()
# unique_depts = report_data[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
# unique_reportees = report_data[["Branch Name", "Department Name", "Direct Reporting"]].drop_duplicates().to_dict(orient = "records")
# unique_combos = {
# "Branch Name": unique_branches,
# "Department Name": unique_depts,
# "Direct Reporting": unique_reportees
# }
# report_data = unique_combos
report_data = report_data.to_dict(orient = "records")
success = True
# ┳┓