Coder Social home page Coder Social logo

superset_pdf_xlsx's Introduction

PDF from webpage and XLSX from table (dynamic webpage)

Designed to work with custom ApacheSuperset charts.

JS part

NOTE

Contains custom style fixes and some bug fixes for original packages.

Allows you to get the generated pdf(A4 landscape format) from a page with expanded content.

Run script

getPdf();

Returns: binary file object.

Allows you to get a styled xlsx file from a table.

Run script

saveTable2XLSX($(".pvtTable")[0], "Table title");

Returns: binary file object.

JS requirements:

NOTE

These modules are expected to be imported into the page with requirements:

Python module selenium_js_executor

Module contains decorator exec_js_wrapper that makes it easier to work with selenium by returning a prepared and configured webdriver.

Decorator params:

  • callable, - decorated function.
  • default_driver:AnyDriver = Firefox, - target webdriver for work.
  • driver_opt:Dict[str, Any] = {}, - addition options for webdriver.
  • headless:bool = True, - separated headless webdriver option.
  • window_size:Tuple[int, int] = (1850, 1132) - separated window_size webdriver option.

Decorated params:

  • url: str - url of target page.
  • wait_until: Optional[ExceptedCondition] = None - optional ExceptedCondition callable object from selenium.webdriver.support when we need wait some event before processing.
  • wait_timeout:int = 600 - timeout for condition waiting.
  • *args
  • **kwargs

Example:

Using Decorator

# Using default decorator params
@exec_js_wrapper
def bpdf_from_url(driver:'WebDriver', *args, **kwargs) -> bytes:
    """Returns binary pdf of page."""
    script = 'return getPdf();'
    result = base64.b64decode(
        driver.execute_script(script)
    )
    return result

The function to be decorated must have the driver as input parameters to work directly with selenium.webdriver.

Using Decorated function:

url = "example.com"
wait_condition = selenium_js_executor.expected_conditions.invisibility_of_element_located(
    (selenium_js_executor.By.XPATH, '//*[@id="load"]')
)
timeout = 600

pdf_data_1 = bpdf_from_url(url, wait_condition, timeout)
open('result_1.pdf', 'wb').write(pdf_data_1)

superset_pdf_xlsx's People

Contributors

yurass13 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.