Пример #1
0
def create_page():
  page = pk.Page()
  template = page.body.add_template(defined_style="margins")
  template.style.css.background = "white"

  dt = page.ui.texts.date("Y-0", html_code='date_from', width=(100, "%"))
  page.ui.navigation.shortcut([
    page.ui.layouts.hr(),
    page.ui.titles.title("Dates"),
    page.ui.titles.bold("From:", align="left"),
    dt,
    page.ui.titles.bold("To:", align="left"),
    page.ui.texts.date(html_code='date_to', width=(100, "%"), options={"date_from_js": "COB"}),
    page.ui.layouts.hr(),
    page.ui.titles.title("Actions"),
    page.ui.input("GS", html_code="input"),
    page.ui.buttons.refresh("Load", html_code="button"),
    page.ui.icons.date(),
    page.ui.div([
      page.ui.icons.awesome("far fa-file-pdf", width=15),
      page.ui.icons.awesome("fas fa-at", width=15),
    ]).css({"bottom": '10px', 'position': 'absolute', 'display': 'block'})
  ], size=(100, 'px'), options={"position": 'left'})

  page.body.style.css.margin_left = 10
  content = ""
  title = page.ui.title(content, options={"markdown": True})
  table = page.ui.tables.tabulators.figures(
    rows=["Date", "Name"], cols=["Low", "High", 'Open', 'Close', 'Volume', 'Adj Close'])

  footer = page.ui.navigation.footer('@Data from pandas_datareader using yahoo as source.')

  page.components['button'].click([
    page.components["button"].icon.dom.spin(True),
    page.js.post("/viewer", {"button": 'Data 1'}, components=[page.components["input"],
      page.components['date_from'], page.components['date_to']]).onSuccess([
      title.build(pk.events.data["title"]),
      table.build(pk.events.data["table"]),
      page.components["button"].icon.dom.spin(False)
    ]),
  ])
  page.components["input"].enter([page.components['button'].dom.events.trigger("click")])
  footer.style.css.padding_left = 110
  return page
Пример #2
0
def create_page():
    page = pk.Page()
    page.headers.dev()

    title = page.ui.title("Flask - First example")
    input = page.ui.inputs.left(placeholder="Enter your name", html_code="msg")
    button = page.ui.buttons.colored("Click")
    text = page.ui.text()
    simple_modal = page.ui.modals.popup([text])
    input.enter([button.dom.events.trigger("click")])
    button.click([
        page.js.post("/test_event", components=[input]).onSuccess(
            [text.build(pk.events.data["message"]),
             simple_modal.dom.show()])
    ])

    box = page.ui.div()
    box.extend([title, input, button])
    box.style.configs.doc()
    return page
Пример #3
0
def create_page():
    page = pk.Page()
    page.body.template.style.configs.margins()

    qrcode = page.ui.qrcode(
        "https://github.com/epykure/epyk-templates/blob/master/tutos/onepy/fastapi_webscraping.py"
    )
    qrcode.style.css.fixed(bottom=60, right=70)
    qrcode.style.css.cursor = "pointer"
    qrcode.style.css.z_index = 300

    dt_from = page.ui.date(html_code='from', width=(120, "px"))
    dt_from.input.style.css.margin_bottom = 10
    dt_to = page.ui.date("2021-05-15", html_code='to', width=(120, "px"))
    dt_to.input.style.css.margin_bottom = 10
    prices = page.ui.button("Get Prices", icon="fab fa-python")
    prices.style.css.padding_left = 10
    prices.style.css.padding_right = 10
    prices.style.css.color = page.theme.colors[-1]
    bar = page.ui.navbar()
    bar.style.css.background = page.theme.colors[-1]
    bar.style.css.color = "white"
    bar.add(dt_from)
    bar.add(dt_to)
    bar.add(prices)
    page.ui.title("Eurostar average prices")
    line = page.ui.charts.chartJs.line(
        y_columns=['standard', 'premier', 'business'], x_axis='full_date')
    bar = page.ui.charts.chartJs.bar(y_columns=['average'], x_axis='category')
    row = page.ui.row([line, bar])
    row.set_size_cols(8)
    prices.click([
        prices.icon.dom.spin(True),
        page.js.post("/web_scrapping", components=[dt_from, dt_to]).onSuccess([
            line.build(pk.events.data["prices"]),
            bar.build(pk.events.data["average"]),
            prices.icon.dom.spin(False)
        ])
    ])
    return page
Пример #4
0
def create_page():
    page = pk.Page()
    page.body.template.style.configs.doc(background="white")

    table = page.ui.table(mocks.popularity_2020)
    table.options.paginationSize = 10

    toggle = page.ui.toggle({
        "on": "Trend",
        "off": "Share"
    },
                            html_code="toggle")
    bar = page.ui.charts.bar(mocks.popularity_2020,
                             y_columns=["Share"],
                             x_axis="Language")

    toggle.click([
        page.js.post("/data", components=[toggle.input]).onSuccess([
            bar.build(pk.events.data["chart_data"],
                      options={"y_columns": pk.events.data["columns"]})
        ])
    ])

    return page
Пример #5
0
import epyk as pk
from epyk.tests import data_urls

page = pk.Page()
page.body.style.css.padding_h = 10  # Add padding to the body
# get data from external github repository and create a filter group
records = page.py.requests.csv(data_urls.DEMO_COUNTRY)
grp = page.data.js.record(records).filterGroup("aggData")
# Autocomplete component.
countries = page.ui.inputs.autocomplete(placeholder="select a country")
countries.options.source = sorted(
    list(set([rec['Country Name'] for rec in records])))
# container to store the selected items when enter is pressed.
cols_keys = page.ui.lists.drop(html_code="cols_agg_keys")
cols_keys.style.css.min_height = 20
cols_keys.items_style(style="bullets")
cols_keys.drop()
# enter event on the input autocomplete component.
countries.enter(
    [cols_keys.dom.add(countries.dom.content),
     countries.dom.empty()])
# write result to static file.
page.outs.html_file(name="outAutocomplete")
Пример #6
0
import epyk as pk


# Create a basic report object
page = pk.Page(
  {'test': "this is a text",
   'test2': "this is a div"}
)
page.headers.dev()

page.ui.text(html_code="test")
page.ui.div(html_code="test2")

Пример #7
0
def create_page():
    page = pk.Page()

    css = pk.CssInline()
    css.margin_bottom = 5
    css.margin_left = 5
    css.important(["margin_bottom", "margin_left"])

    autocomp = page.ui.inputs.autocomplete(placeholder="script name",
                                           html_code="name",
                                           options={"borders": "bottom"})
    autocomp.options.select = True
    version = page.ui.select(width=(100, 'px'), html_code="selected_version")
    version.attr["class"].add(css.to_class("cssTestClass"))
    version.options.noneSelectedText = "None"
    button = page.ui.buttons.colored("Load")
    button.style.css.margin_left = 10

    page.ui.navbar(components=[autocomp, version, button])

    script = page.ui.text("script name", html_code="script")
    script.options.editable = True
    script.style.css.bold()
    pkg_version = page.ui.text("Version")
    pkg_number = page.ui.text("0.0.0", html_code="version")
    pkg_number.options.editable = True
    pkg_number.style.css.margin_left = 10
    v = page.ui.div([pkg_version, pkg_number], width="auto")
    v.style.css.float = "right"
    v.style.css.display = "inline-block"

    i1 = page.ui.icon("fas fa-edit")
    i2 = page.ui.icon("fas fa-lock")
    i3 = page.ui.icon("fas fa-save")
    actions = page.ui.div([i1, i2, i3], width=(20, 'px'))
    actions.style.css.position = "absolute"
    actions.style.css.top = 60
    actions.style.css.right = 0
    actions.style.css.padding_left = "3px"
    actions.style.css.border_radius = "5px 0 0 5px"
    actions.style.css.background = page.theme.greys[3]

    header = page.ui.div([script, v])
    header.style.css.background = page.theme.greys[2]
    header.style.css.display = "block"
    header.style.css.padding_h = 15

    title = page.ui.title("Documentation Viewer", html_code="title")
    title.options.editable = True
    content = page.ui.rich.markdown(__doc__, html_code="content")
    content.options.editable = True

    banner = page.ui.text("Editable", width=(75, 'px'))
    banner.style.css.background = page.theme.success[1]
    banner.style.css.border_radius = "0 0 20px 0"
    banner.style.css.padding_h = 10
    banner.style.css.font_factor(-2)
    banner.style.css.color = page.theme.greys[-1]
    banner.style.css.position = "absolute"
    banner.style.css.bold()
    banner.style.css.top = 0
    banner.style.css.left = 0

    container = page.ui.div([banner, header, title, content, actions])
    container.style.configs.doc(background="white")
    container.style.css.position = "relative"
    container.style.css.padding_top = 30

    updt = page.ui.rich.update(align="right", html_code="last_update")
    updt.style.css.italic()
    updt.style.css.font_factor(-2)
    container.add(updt)

    i3.click([
        page.js.post("/save",
                     components=[
                         banner, script, pkg_number, title, content, updt
                     ]).onSuccess([page.js.msg.status(),
                                   updt.refresh()])
    ])

    i1.click([
        script.dom.setAttribute("contenteditable", True).r,
        pkg_number.dom.setAttribute("contenteditable", True).r,
        title.dom.setAttribute("contenteditable", True).r,
        content.dom.setAttribute("contenteditable", True).r,
        page.js.msg.text("Components editable"),
        banner.build("Editable"),
        banner.dom.css({
            "background": page.theme.success[1],
            "color": page.theme.greys[-1]
        })
    ])

    i2.click([
        script.dom.setAttribute("contenteditable", False).r,
        pkg_number.dom.setAttribute("contenteditable", False).r,
        title.dom.setAttribute("contenteditable", False).r,
        content.dom.setAttribute("contenteditable", False).r,
        page.js.msg.text("Components locked"),
        banner.build("Locked"),
        banner.dom.css({
            "background": page.theme.colors[-1],
            "color": page.theme.greys[0]
        })
    ])

    autocomp.enter([
        page.js.post("/versions", components=[autocomp]).onSuccess([
            version.build(pk.events.data["versions"]),
            version.js.val(pk.events.data["selected"]),
            version.js.refresh(),
            page.js.msg.status()
        ])
    ])

    button.click([
        page.js.post("/details", components=[autocomp, version]).onSuccess([
            title.build(pk.events.data["title"]),
            content.build(pk.events.data["content"]),
            script.build(pk.events.data["script"]),
            pkg_number.build(pk.events.data["number"]),
            updt.build(pk.events.data["last_date"]),
        ])
    ])
    page.body.onReady([
        page.js.post("/templates").onSuccess(
            [autocomp.js.source(pk.events.data["values"])])
    ])
    return page
Пример #8
0
async def get_prices(request: Request):
    data = await request.json()
    page = pk.Page()
    dates = page.py.dates.range_dates(data["from"], data["to"])
    prices, averages = [], {}
    driver = webdriver.Firefox(
        executable_path=r"C:\servers\browsers\geckodriver.exe")
    for date in dates:
        tmp_file = os.path.join("C:/tmps",
                                "eurostar_%s.json" % date.replace("-", ""))
        if not os.path.exists(tmp_file):
            url = 'https://booking.eurostar.com/uk-en/train-search?origin=7015400&destination=8727100&adult=1&outbound-date=%s' % date
            driver.get(url)
            time.sleep(3)
            content = driver.page_source
            soup = BeautifulSoup(content, features="lxml")
            results, row = [], {}
            categories = ['standard', 'premier', 'business']
            for i, t in enumerate(
                    soup.find_all("section",
                                  {'class': 'train__class-of-accommodation'})):
                if i % 3 == 0 and row:
                    results.append(row)
                    row = {}
                if t.find("div", {"class": 'coa__price-container'}) is None:
                    row[categories[i % 3]] = None
                else:
                    row[categories[i % 3]] = t.find(
                        "div", {
                            "class": 'coa__price-container'
                        }).find("span", {
                            "class": 'price price--gbp'
                        }).text
            results.append(row)
            for i, t in enumerate(
                    soup.find_all("section", {'class': 'journey-details'})):
                results[i]['time'] = t.find("li", {
                    'class': 'item-depart'
                }).text
                results[i]['date'] = date
            with open(tmp_file, "w") as f:
                json.dump(results, f)
        else:
            with open(tmp_file) as f:
                results = json.load(f)
        for rec in results:
            if 'time' in rec:
                rec['full_date'] = "%s %s" % (date, rec['time'])
                for p in ['standard', 'premier', 'business']:
                    rec[p] = float(
                        rec[p][1:]) if rec[p] is not None else rec[p]
                    if p not in averages:
                        averages[p] = {"sum": 0, "count": 0}
                    averages[p]["sum"] += rec[p]
                    averages[p]["count"] += 1
        prices.extend(results)
    driver.quit()
    return {
        "prices":
        prices[::-1],
        "average": [{
            "category": k,
            "average": v["sum"] / v["count"]
        } for k, v in averages.items()]
    }
Пример #9
0
def create_page():
    page = pk.Page()

    qrcode = page.ui.qrcode(
        "https://github.com/epykure/epyk-templates/blob/master/tutos/onepy/fastapi_viewer_logs.py"
    )
    qrcode.style.css.fixed(bottom=60, right=70)
    qrcode.style.css.cursor = "pointer"
    qrcode.style.css.z_index = 300

    template = page.body.add_template(defined_style="margins")

    epyk = page.ui.icons.epyk()
    epyk.style.css.margin_right = 10

    template.style.css.padding_top = 40
    dt_from = page.ui.date(icon=False, width=120, html_code="from")
    dt_from.tooltip("From Date")
    dt_to = page.ui.date(width=120, icon=False, html_code="to")
    dt_to.tooltip("To Date")
    dt_to.style.css.margin_left = 10
    dt_to.style.css.margin_right = 10
    select = page.ui.select(components.select.from_list(
        ["Info", "Debug", "Warning"]),
                            width=(80, "px"),
                            html_code="log_typ")
    search = page.ui.rich.search_input(width=(100, 'px'),
                                       color="white",
                                       extensible=True,
                                       options={
                                           "icon": False,
                                           "borders": "bottom"
                                       },
                                       html_code="search")
    search.style.css.margin_left = 10
    search.input.style.css.color = "white !IMPORTANT"
    text = page.ui.text()
    button = page.ui.buttons.colored("Get")
    button.style.css.margin_left = 20
    button.style.css.padding_left = 20
    button.style.css.padding_right = 20
    search.enter([button.dom.events.trigger("click")])

    bar = page.ui.div([epyk, dt_from, dt_to, select, search, text, button])
    bar.style.css.fixed(left=0, top=0)
    bar.style.css.background = page.theme.notch()
    bar.style.css.color = "white"
    bar.components.css({"display": 'inline-block'})

    page.ui.title("log Analyzer")
    console = page.ui.rich.console(height="auto", options={"markdown": True})
    console.style.css.overflow = None

    button.click(
        page.js.post("/viewer",
                     components=[dt_from, dt_to, select, search],
                     profile=True).onSuccess([
                         console.dom.write(pk.events.data["message"]),
                         page.js.console.log("Log message")
                     ]))
    return page