fix(berlin/immigration): prevent crashes on due to page.pause()

This commit is contained in:
2023-02-20 15:33:08 +01:00
parent e63ab7b77e
commit d5484492b1
+17 -7
View File
@@ -38,6 +38,7 @@ def alert(text: str):
dump_dir = Path('~/Desktop').expanduser() / 'immigration'
dump_dir.mkdir(parents=True, exist_ok=True)
async def check_slots(page: Page, retry_count: int = 1) -> list[datetime.datetime]:
await page.add_init_script('''Object.defineProperty(navigator, 'webdriver', { get: () => false })''')
window_id = random.randint(1000, 9999)
@@ -96,13 +97,24 @@ async def check_slots(page: Page, retry_count: int = 1) -> list[datetime.datetim
continue
if 'st=3' in page.url:
alert('empty slot found')
dates = []
for el in await page.query_selector_all('.ui-datepicker-calendar td:not(.ui-datepicker-unselectable)'):
dates.append(
datetime.date(
year=int(await el.get_attribute('data-year')),
month=int(await el.get_attribute('data-month')),
day=int(await el.inner_text()),
)
)
alert("\n".join(['empty slots found', *[it.isoformat() for it in dates]]))
now = int(datetime.datetime.now().timestamp())
html_path = dump_dir / f'immigration_{now}.html'
html_path.write_text(await page.content())
await page.screenshot(path=dump_dir/f'immigration_{now}.png')
await page.screenshot(path=dump_dir / f'immigration_{now}.png')
await page.pause()
input()
input()
@@ -112,9 +124,7 @@ def parse_args():
arger.add_argument(
'--headless', '--silent', '--quiet', action='store_true', dest='headless', help='Run in headless mode'
)
arger.add_argument(
'--retry-count', '--retry', type=int, default=1, help='Run in headless mode'
)
arger.add_argument('--retry-count', '--retry', type=int, default=1, help='Run in headless mode')
args, _ = arger.parse_known_args()
return args
@@ -130,7 +140,7 @@ async def main():
return
except Exception as e:
logging.exception('got an error')
await page.pause()
input()
if __name__ == '__main__':