示例#1
0
def main_page():
    response = requests.get('https://aws.random.cat/meow')
    cat_picture_url = json.loads(response.content)['file']

    response = requests.get('https://cat-fact.herokuapp.com/facts/random')
    cat_fact = json.loads(response.content)['text']

    return str(html(body(img(src=cat_picture_url), p(cat_fact))))
示例#2
0
def build_html(shapes=None, body_width=1000):
    """
    """
    assert isinstance(shapes, (tuple, list))

    if not shapes:
        shapes = []
        shapes.extend((
            Rect(0, 0, 800, 500),
            Rect(0, 510, 800, 300),
            Rect(0, 810, 800, 300),
        ))

    elements = []

    for n, shape in enumerate(shapes):
        assert isinstance(shape, Shape)
        el_id = shape.name + str(n)
        el = Element(el_id)
        el.html = pyhtml.div(id=el_id)
        el.css = shape.css(el_id)

        elements.append(el)

    # byg HTML

    head = pyhtml.head(pyhtml.meta(charset="utf-8"), pyhtml.title("DrawHTML"),
                       pyhtml.link(rel="stylesheet", href="PATH/TO/CSS"))
    divs = [x.html for x in elements if x.html]

    root_id = "root"
    root_el = Element(root_id)
    root_el.html = pyhtml.div(*divs)
    root_el.css =  "#{} {{ \n".format(root_id) \
            + "position: absolute; \n" \
            + "left: 0px; \n" \
            + "right: 0px; \n" \
            + "margin-right: auto; \n" \
            + "margin-left: auto; \n" \
            + "width: {}px; \n".format(body_width) \
            + "}\n"
    root_el.html.attributes['id'] = root_id
    elements.append(root_el)

    body = pyhtml.body(root_el.html)

    h = pyhtml.html(head, body)

    css = "* {" \
        + "margin: 0;" \
        + "padding: 0;" \
        + "}\n"

    for x in elements:
        css += x.css

    return h, css
示例#3
0
def hello():
    example_form = form(action="goodbye")(label(
        "Enter a message:", input_(type="text", name="message"),
        input_(type="submit")))
    response = html(
        body(
            h1("Welcome"),
            p("Hello, how are you?"),
            # <a href="https://google.com">Go to google</a>
            a(href="https://google.com")("Go to google"),
            img(src="https://source.unsplash.com/J1E6XzW1INk", width=500),
            example_form))
    return str(response)
示例#4
0
def processVisited(pathToFile):
    #print(pathToFile + " szar")
    menuElements = []
    with open(pathToFile) as json_file:
        data = json.load(json_file)
        for key in data["visited_things"]:
            name = functions.encodeText(str(key['name']))
            print(name)
            print(str(key))
            menuElements.append((name, name))

    def f_links(ctx):
        for title, page in menuElements:
            yield ph.li(ph.a(href=page)(title))
    t = ph.html(
        ph.head(
            ph.title('visited_things'),
            ph.script(src="http://path.to/script.js")
        ),
        ph.body(
            ph.header(
                ph.img(src='/path/to/logo.png'),
                ph.nav(
                    ph.ul(f_links(menuElements))
                )
            ),
            ph.div(
                lambda ctx: "Hello %s" % ctx.get('user', 'Guest'),
                'Content here'
            ),
            ph.footer(
                ph.hr,
                'Copyright 2013'
            )
        )
    )
    resultFile = FOLDER_GEN_HTML + "\\" + "sample.html"
    with open(resultFile, "w", encoding="utf-8") as newFile:
        newFile.write(t.render(user='******'))
    newFile.close()

    print(str(menuElements))

    exit()
示例#5
0
    def html(self):
        trs = [self.get_title()]
        for d in self.data.values:
            trs.append(self.get_tr(d))

        return html(body(table(trs)))
示例#6
0
def main_page():
    result = ""
    if not 'id' in session:
        session['id'] = random.randint(0, 1000000000000)
        session['correct'] = 0
        session['total'] = 0

    if request.method == 'POST':
        if 'first_choice' in request.form:
            tweet = session['first_tweet']
        else:
            tweet = session['second_tweet']

        if tweet in elon_tweets:
            result = "Correct"
            session['correct'] = int(session['correct']) + 1
        else:
            result = "Incorrect"
        session["total"] = int(session['total']) + 1

        store_result(session['id'], session['first_tweet'],
                     session['second_tweet'], tweet, result)

        del session['first_tweet']
        del session['second_tweet']

    if 'first_tweet' in session:
        first_tweet = session['first_tweet']
        second_tweet = session['second_tweet']
    else:
        fake_tweet = None
        while fake_tweet == None or fake_tweet in elon_tweets:
            fake_tweet = generate_tweet(word_map, prefix_length)
        real_tweet = random.choice(elon_tweets)

        if random.randint(0, 1) == 0:
            first_tweet = fake_tweet
            second_tweet = real_tweet
        else:
            first_tweet = real_tweet
            second_tweet = fake_tweet

    session['first_tweet'] = first_tweet
    session['second_tweet'] = second_tweet

    header = head(
        link(
            rel="stylesheet",
            href="https://unpkg.com/[email protected]/build/pure-min.css",
            integrity=
            "sha384-LTIDeidl25h2dPxrB2Ekgc9c7sEC3CWGM6HeFmuDNUjX76Ert4Z4IY714dhZHPLd",
            crossorigin="anonymous"),
        link(rel="stylesheet", href="static/style.css"))

    choice_form = form(action='/')(
        # The result of the users last choice
        p(result),
        # The first tweet
        div(class_="tweet-container")(p(first_tweet)),
        # The button to choose the first tweet
        input_(type="submit",
               class_="pure-button pure-button-primary",
               name="first_choice",
               value="This is the real tweet"),
        # The second tweet
        div(class_="tweet-container")(p(second_tweet)),
        # The button to choose the second tweet
        input_(type="submit",
               class_="pure-button pure-button-primary",
               name="second_choice",
               value="This is the real tweet"),
        # The number of tweets identified
        p(
            str(session['correct']) + '/' + str(session['total']) +
            ' tweets correctly identified'))

    response = html(
        header, body(div(class_="content")(h1("Musk or Bot"), choice_form)))
    return str(response)