87 lines
3.4 KiB
Python
87 lines
3.4 KiB
Python
from playwright.sync_api import sync_playwright
|
|
import os
|
|
|
|
# ── CONFIG ──────────────────────────────────────────────────────────────────
|
|
BASE_URL = "https://janssen.4gclinical.com"
|
|
|
|
EMAIL = "vbuzalka@its.jnj.com"
|
|
PASSWORD = "Vlado123++-+"
|
|
|
|
# STUDY = "42847922MDD3003"
|
|
STUDY = "77242113UCO3001"
|
|
|
|
OUTPUT_DIR = f"xls_shipment_details_{STUDY}"
|
|
# ────────────────────────────────────────────────────────────────────────────
|
|
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
|
|
def download_shipment_details():
|
|
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)
|
|
|
|
browser.close()
|
|
print("\nHotovo!")
|
|
|
|
|
|
download_shipment_details()
|