-
Notifications
You must be signed in to change notification settings - Fork 0
/
browsy.py
59 lines (44 loc) · 1.64 KB
/
browsy.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
import json
import sys
import logging
from playwright.sync_api import Playwright, sync_playwright, expect
from pathlib import Path
def run(playwright: Playwright, dictionary) -> None:
# Switch from DEBUG to CRITICAL to reduce verbosity
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
# Read dictionary from file
with open(dictionary) as file:
data = file.read()
js = json.loads(data)
logging.debug(f'Data from file: {js}')
chromium_dir = Path.home() / '.config/chromium'
logging.debug(f'chromium_dir is: {chromium_dir}')
browser = playwright.chromium.launch_persistent_context(chromium_dir, headless=False)
page = browser.new_page()
page.goto(js["$HOME_PAGE"])
# TODO: Add "Browsy" ASCII logo
print("Use command 'help' for list of available commands")
while 1:
cmd = input("--> ")
if cmd == 'help':
print("available commands: dump, exit, goto, help, simple")
if cmd == 'exit':
exit()
if cmd == 'simple':
page.goto("https://phet-dev.colorado.edu/html/build-an-atom/0.0.0-3/simple-text-only-test-page.html")
if cmd == 'dump':
print(page.content())
if cmd == 'goto':
url = input("URL: ")
# append https:// to start of URL if not provided.
if not url.startswith("http"):
url = f"https://{url}"
page.goto(url)
prog_name = sys.argv[0]
if len(sys.argv) != 2:
print(f"usage: {prog_name} <dictionary file>")
exit()
with sync_playwright() as playwright:
run(playwright, sys.argv[1])
# TODO - Add ASCII intro text