53 lines
No EOL
2.5 KiB
Python
53 lines
No EOL
2.5 KiB
Python
import asyncio, json
|
|
from playwright.async_api import async_playwright
|
|
|
|
async def main():
|
|
async with async_playwright() as p:
|
|
b = await p.chromium.launch(args=["--no-sandbox"])
|
|
pg = await b.new_page(viewport={"width": 1500, "height": 1000})
|
|
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000)
|
|
await pg.wait_for_timeout(2500)
|
|
await pg.click('#tabs button[data-view="calendar"]')
|
|
await pg.wait_for_timeout(2500)
|
|
|
|
r = await pg.evaluate("""() => {
|
|
const v = document.getElementById('view-calendar');
|
|
const out = {days: [], range: null, today: null, latinNums: [], overflows: []};
|
|
|
|
out.range = v.querySelector('.cal-range')?.innerText.trim();
|
|
|
|
// what does the page think today is?
|
|
out.today = {
|
|
todayJalaliChip: document.getElementById('todayJalali')?.innerText.trim(),
|
|
markedToday: v.querySelector('.day.today .day-num')?.innerText.trim(),
|
|
markedTodayName: v.querySelector('.day.today .day-name')?.innerText.trim(),
|
|
jsNow: new Date().toISOString().slice(0,10)
|
|
};
|
|
|
|
v.querySelectorAll('.day').forEach(d => {
|
|
const name = d.querySelector('.day-name')?.innerText.trim();
|
|
const num = d.querySelector('.day-num')?.innerText.trim();
|
|
const hrs = d.querySelector('.day-hours')?.innerText.trim();
|
|
const tasks = [...d.querySelectorAll('.mini-task')].map(t => t.innerText.trim());
|
|
out.days.push({name, num, hrs, isToday: d.classList.contains('today'),
|
|
taskCount: tasks.length, tasks: tasks.slice(0,4)});
|
|
// latin digits inside any numeric display
|
|
[num, hrs].forEach(s => {
|
|
if (s && /[0-9]/.test(s)) out.latinNums.push(s);
|
|
});
|
|
if (hrs && /\\./.test(hrs)) out.latinNums.push('DOT:' + hrs);
|
|
});
|
|
|
|
// clipping inside the calendar grid
|
|
v.querySelectorAll('*').forEach(el => {
|
|
if (el.scrollWidth - el.clientWidth > 2 && el.clientWidth > 0)
|
|
out.overflows.push({cls: (el.className||'').toString().slice(0,30),
|
|
over: el.scrollWidth - el.clientWidth,
|
|
txt: (el.innerText||'').replace(/\\s+/g,' ').slice(0,40)});
|
|
});
|
|
return out;
|
|
}""")
|
|
print(json.dumps(r, ensure_ascii=False, indent=2))
|
|
await b.close()
|
|
|
|
asyncio.run(main()) |