Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
  • Loading branch information
alpha-xone committed Aug 12, 2021
1 parent 3b3b938 commit 0cdf89c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# vscode settings
.vscode/
2 changes: 1 addition & 1 deletion xone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Frequently used functions for financial data analysis"""

__version__ = '0.1.7b7'
__version__ = '0.1.7b8'

__submodules__ = [
'utils',
Expand Down
33 changes: 31 additions & 2 deletions xone/browser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import requests
import time
import os
import shutil

from xone import logs
from xone import logs, files
from collections import namedtuple
from bs4 import BeautifulSoup
from selenium import webdriver
Expand Down Expand Up @@ -35,13 +37,40 @@ def to_text(soup, elem_name, func: callable = None) -> list:
]


def get_browser(browser, headless=True, *args):
def get_rel_path(folder: str, home=os.path.expanduser('~')) -> str:
"""
Get relative path from home folder
"""
return (
f'{home}/{folder}'
.replace('/', os.path.sep)
.replace('\\', os.path.sep)
)


def get_browser(browser, headless=True, download='', *args):
"""
Get browser
Args:
browser: one of firefox and chrome
headless: whether to show browser
download: folder to download files to - relative to ~/Downloads
files in the folder WILL BE REMOVED when browser is returned
"""
br, br_opt = BROWSERS[browser]
if headless: br_opt.add_argument('--headless')
br_opt.add_argument('--disable-gpu')
br_opt.add_experimental_option('excludeSwitches', ['enable-logging'])
if download:
dl_path = get_rel_path(folder=f'Downloads/{download}')
if files.exists(dl_path): shutil.rmtree(dl_path, ignore_errors=True)
files.create_folder(dl_path)
br_opt.add_experimental_option('prefs', {
'download.default_directory': dl_path,
'download.prompt_for_download': False,
'download.directory_upgrade': True,
})
for arg in args: br_opt.add_argument(arg)
return br(options=br_opt)

Expand Down

0 comments on commit 0cdf89c

Please sign in to comment.