-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpythonrc.py
66 lines (50 loc) · 1.88 KB
/
pythonrc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# A dev pythonrc module.
# I use this module for interactive debugging. It is automatically loaded
# in my (b)python setup and provides convenient bindings.
import asyncio
import atexit
import decimal
import json
import pathlib
import playwright
from playwright.async_api import async_playwright
from selenium import webdriver
import fetcher.tool as t
from fetcher import op # noqa: F401
from fetcher.playwrightutils import (
Browser,
get_browser_type,
)
D = decimal.Decimal
with open(t.FETCHER_CONFIG_DEFAULT, 'r') as cf:
config = json.load(cf)
revolut_account_numbers = config['revolut_account_numbers']
def start_driver():
driver = webdriver.Firefox()
driver.implicitly_wait(20)
return driver
loop = asyncio.new_event_loop()
atexit.register(loop.close)
def ruc(a):
return loop.run_until_complete(a)
async def start_playwright(
browser_spec: Browser = Browser.FIREFOX
) -> tuple[playwright.async_api.Playwright, playwright.async_api.Browser,
playwright.async_api.BrowserContext, playwright.async_api.Page]:
"""Starts a synchronous Playwright instance.
:rtype tuple[playwright.async_api.Playwright,
playwright.async_api.Browser,
playwright.async_api.Page]
"""
downloads_dir = pathlib.Path.home().joinpath('Downloads')
pw = await async_playwright().start()
browser_type = get_browser_type(pw, browser_spec)
browser = await browser_type.launch(headless=False,
downloads_path=downloads_dir)
# no_viewport=True disables the default fixed viewport and lets the site
# adapt to the actual window size
context = await browser.new_context(no_viewport=True)
p = await context.new_page()
return (pw, browser, context, p)
async def open_1password_client() -> op.OpSdkClient:
return await op.OpSdkClient.connect(op.fetch_service_account_auth_token())