z230
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from playwright.sync_api import sync_playwright
|
||||
import os
|
||||
import pandas as pd
|
||||
|
||||
# ── CONFIG ──────────────────────────────────────────────────────────────────
|
||||
BASE_URL = "https://janssen.4gclinical.com"
|
||||
@@ -7,80 +8,88 @@ BASE_URL = "https://janssen.4gclinical.com"
|
||||
EMAIL = "vbuzalka@its.jnj.com"
|
||||
PASSWORD = "Vlado123++-+"
|
||||
|
||||
# STUDY = "42847922MDD3003"
|
||||
STUDY = "77242113UCO3001"
|
||||
STUDY = "42847922MDD3003"
|
||||
#STUDY = "77242113UCO3001"
|
||||
|
||||
OUTPUT_DIR = f"xls_shipment_details_{STUDY}"
|
||||
# ────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||
def get_cz_shipment_ids(study):
|
||||
path = f"xls_shipments_{study}/shipments_report_{study}.xlsx"
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
df = pd.read_excel(path, header=5)
|
||||
df.columns = df.columns.str.strip()
|
||||
df = df.dropna(how="all")
|
||||
df["Shipment ID"] = df["Shipment ID"].astype(str).str.strip()
|
||||
cz = df[df["Location"].str.contains("Czech", na=False, case=False)]
|
||||
return cz["Shipment ID"].tolist()
|
||||
|
||||
|
||||
def download_shipment_details():
|
||||
def run(page, study):
|
||||
output_dir = f"xls_shipment_details_{study}"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
page.goto(f"{BASE_URL}/report/shipment_details_report")
|
||||
page.wait_for_load_state("networkidle", timeout=120000)
|
||||
|
||||
cz_ids = get_cz_shipment_ids(study)
|
||||
if cz_ids is not None:
|
||||
shipments = cz_ids
|
||||
print(f" Filtrovano ze shipments reportu: {len(shipments)} CZ shipmentu")
|
||||
else:
|
||||
page.locator('input[placeholder="search"], input[type="text"]').first.click()
|
||||
page.wait_for_timeout(1000)
|
||||
shipments = [s.strip() for s in page.locator('mat-option').all_inner_texts()
|
||||
if s.strip() and s.strip() != "No results found"]
|
||||
print(f" Nalezeno {len(shipments)} shipmentu z dropdownu")
|
||||
page.keyboard.press("Escape")
|
||||
page.wait_for_timeout(500)
|
||||
|
||||
if not shipments:
|
||||
print(" Zadne shipments — preskakuji.")
|
||||
return
|
||||
|
||||
for shipment in shipments:
|
||||
filename = os.path.join(output_dir, f"shipment_details_{shipment}.xlsx")
|
||||
if os.path.exists(filename):
|
||||
print(f" [{shipment}] Preskakuji — existuje.")
|
||||
continue
|
||||
print(f" [{shipment}] Stahuji...")
|
||||
|
||||
input_field = page.locator('input[placeholder="search"], input[type="text"]').first
|
||||
input_field.click()
|
||||
input_field.fill(shipment)
|
||||
page.wait_for_timeout(500)
|
||||
page.locator('mat-option').first.dispatch_event('click')
|
||||
page.wait_for_load_state("networkidle", timeout=120000)
|
||||
|
||||
with page.expect_download(timeout=120000) as dl:
|
||||
page.get_by_role("button", name="Download XLS").click()
|
||||
dl.value.save_as(filename)
|
||||
print(f" [{shipment}] OK")
|
||||
|
||||
page.get_by_role("button", name="Clear").click()
|
||||
page.wait_for_load_state("networkidle", timeout=120000)
|
||||
|
||||
print(" Shipment details hotovo.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from playwright.sync_api import sync_playwright
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=False)
|
||||
context = browser.new_context(accept_downloads=True)
|
||||
page = context.new_page()
|
||||
|
||||
# Prihlaseni
|
||||
page.goto(BASE_URL)
|
||||
page.wait_for_load_state("networkidle")
|
||||
page.get_by_label("Email *").fill(EMAIL)
|
||||
page.get_by_label("Password *").fill(PASSWORD)
|
||||
page.locator('#login__submit').click()
|
||||
page.wait_for_load_state("networkidle")
|
||||
|
||||
# Vyber studie
|
||||
page.get_by_label("Study *").click()
|
||||
page.get_by_role("option", name=STUDY).click()
|
||||
page.get_by_role("button", name="SELECT").click()
|
||||
page.wait_for_load_state("networkidle")
|
||||
|
||||
# Naviguj na Shipment Details Report
|
||||
page.goto(f"{BASE_URL}/report/shipment_details_report")
|
||||
page.wait_for_load_state("networkidle", timeout=15000)
|
||||
|
||||
# Precti dostupne shipments z dropdownu
|
||||
page.locator('input[placeholder="search"], input[type="text"]').first.click()
|
||||
page.wait_for_timeout(1000)
|
||||
shipments = [s.strip() for s in page.locator('mat-option').all_inner_texts()
|
||||
if s.strip() and s.strip() != "No results found"]
|
||||
print(f"Nalezeno {len(shipments)} shipmentu: {shipments}")
|
||||
page.keyboard.press("Escape")
|
||||
page.wait_for_timeout(500)
|
||||
|
||||
if not shipments:
|
||||
print("Zadne shipments nenalezeny — konec.")
|
||||
browser.close()
|
||||
return
|
||||
|
||||
for shipment in shipments:
|
||||
safe_name = shipment.replace("/", "-").replace("\\", "-").replace(" ", "_")
|
||||
filename = os.path.join(OUTPUT_DIR, f"shipment_details_{safe_name}.xlsx")
|
||||
if os.path.exists(filename):
|
||||
print(f"[{shipment}] Preskakuji — soubor jiz existuje.")
|
||||
continue
|
||||
print(f"[{shipment}] Stahuji...")
|
||||
|
||||
input_field = page.locator('input[placeholder="search"], input[type="text"]').first
|
||||
input_field.click()
|
||||
input_field.fill(shipment)
|
||||
page.wait_for_timeout(500)
|
||||
page.locator('mat-option').first.dispatch_event('click')
|
||||
|
||||
page.wait_for_load_state("networkidle", timeout=30000)
|
||||
|
||||
with page.expect_download(timeout=30000) as dl:
|
||||
page.get_by_role("button", name="Download XLS").click()
|
||||
|
||||
dl.value.save_as(filename)
|
||||
print(f"[{shipment}] Ulozeno -> {filename}")
|
||||
|
||||
page.get_by_role("button", name="Clear").click()
|
||||
page.wait_for_load_state("networkidle", timeout=15000)
|
||||
|
||||
run(page, STUDY)
|
||||
browser.close()
|
||||
print("\nHotovo!")
|
||||
|
||||
|
||||
download_shipment_details()
|
||||
|
||||
Reference in New Issue
Block a user