Exemplo n.º 1
0
def index(req, p):
    users_db = req.settings[u'users_db']
    p(u'Frishy.  Squish your friends!')
    p(html.br())
    p(html.a('/signin', 'sign in'))
    profiles = users_db.view('_design/users/_view/user_profiles', 
                             limit=10, include_docs=True)
    p(html.h2('Profiles:'))
    with html.ul(p):
        for p in profiles:
            url = profile.url(p.doc[u'name'].replace(' ', '_')+u'/'+p.doc.id+u'/')
            p(html.li(html.a(url, p.doc[u'name'])))
Exemplo n.º 2
0
def template_answered_matrix(p, matrix_id, f, answer, guessed):
    with p(html.html()):
        with p(html.head()):
            p(html.title('Answered a matrix'))
    with p(html.body()):
        if answer == guessed:
            p(html.h1('Correct!'))
        else:
            p(html.h1('Sorry, wrong answer :('))
        p(html.h2('You guessed: '))
        p(html.p(html.img(figure_image.url(guessed))))
        p(html.p(html.a(ask_matrix.url(matrix_id), 'Back to this matrix')))
        p(html.p(html.a(generate_random_matrix.url(), 'or Generate a new matrix')))
        p(html.p(html.img(matrix_guess.url(matrix_id))))
Exemplo n.º 3
0
def profile(req, p, remaining):
    users_db = req.settings[u'users_db']
    updates_db = req.settings[u'updates_db']
    session = req.environ['beaker.session']
    session[u'counter'] = session.get('counter', 0) + 1
    session.save()

    user = session[u'user'] if u'user' in session else None
    user_profiles = profiles_of_user(users_db, user)
    p(html.br())

    name, id, _ = remaining.split(u'/', 2)

    updates = updates_db.view('_design/updates/_view/updates_by_profile',
                              startkey=[id], endkey=[id, {}], include_docs=True)
    p(html.h1(name.replace('_', ' ')))

    if user is not None:
        p(u'<form action="%s" method="POST">' % '/say')
        p(u'%s ' % name.replace('_', ' '))
        p(u'<input type="hidden" name="profile" value="%s" />' % id)
        p(u'<input type="text" name="message" value="is "')
        if id in user_profiles:
            p(u'disabled="true"')
        p(u'/>')
        p(u'<input type="submit" value="Say"')
        if id in user_profiles:
            p(u'disabled="true"')
        p(u' />')
        p(u'</form>')
        if id in user_profiles:
            p(u'<p style="font-size:smaller"><em>This is your profile</em>. You may not edit your profile.</p>')
        p(html.br())
        p(html.br())

    updates = list(updates)
    updates.reverse()
    for u in updates:
        p(u[u'value'])
        p(u' <b style="font-size:x-small;">')
        p(webify.templates.helpers.time.fuzzy_time_diff(datetime.datetime.fromtimestamp(u.doc['date'])))
        p(u' ago')
        p(u' <a href="/" style="font-size:xx-small">(by Joseph)</a>')
        p(u'</b>')
        p(html.br())

    friends = users_db.view('_design/users/_view/friends',
                            startkey=[id], endkey=[id, {}], include_docs=True)
    p(html.h2(u'Friends:'))
    with html.ul(p):
        for f in friends:
            if f[u'key'][1] == 1:
                url = profile.url(f.doc[u'name'].replace(' ', '_')+u'/'+f.doc.id+u'/')
                p(html.li(html.a(url, f.doc[u'name'])))

    p(u'Pageviews: %s' % session['counter'])
    p(html.br())
Exemplo n.º 4
0
def financials(req, p, ticker):
    try:
        url, page = seclib.latest_10k_financials(ticker)
        #tables = [t for t in tables if len(t) > 0]
    except:
        p(u'Could not find this ticker on SEC website')
    else:
        try:
            tables_html = extracttable.tables_html_from_page(page)
            tables = [extracttable.table_data_from_html(t) for t in tables_html]
        except:
            p(u'Failed to parse financial data from page: %s' % html.a(url, url))
        else:
            p(template_financials(ticker, tables))
Exemplo n.º 5
0
def upload(req, p):
    if req.method == u'POST':
        short_code = req.params.get('short_code')
        assert(short_code_valid(short_code))
        uploaded_file = req.POST[u'csv']
        assert(uploaded_file.type == u'text/csv')
        assert(uploaded_file.filename.endswith('.csv'))
        data = uploaded_file.file.read()
        csv_location = req.settings[u'csv_location']
        with open(os.path.join(csv_location, short_code), 'w') as f:
            f.write(data)
        save_properties(csv_location, short_code, {})
        p(u'Thank you for uploading %s.  ' % uploaded_file.filename)
        p(html.a(view_csv.url(short_code), u'You can see it here.'))
        #TODO: jperla: redirect to new file; need a 302
    else:
        short_code = hashlib.md5(str(random.random())).hexdigest()[:15]
        p(template_upload_form(short_code))
Exemplo n.º 6
0
def partial_linked_financials_table(t, table, ticker, table_number):
    column_headings = sorted_column_headings_from_table(table)
    with t(html.table(attrs={'width':'100%'})):
        with t(html.thead()):
            t(html.th(u'&nbsp;'))
            t(html.th(u'&nbsp;'))
            for c in column_headings:
                attrs = {'style':'width:70px;text-align:right;v-align:top;'}
                t(html.th(unicode(c), attrs=attrs))

        colors = cycle(['FFFFFF', 'CCFFFF'])
        for color, (line_item, values) in izip(colors, table):
            with t(html.tr({'style':'background-color:%s;' % color})):
                t(html.td(unicode(line_item), attrs={'style':'width:400px;'}))
                t(html.td(u'&nbsp;'))
                for c in column_headings:
                    if c in values:
                        attrs = {'style':
                                    'width:90px;text-align:right;v-align:top;'}
                        num = values[c]
                        link = html.a(originals.url(ticker) + '?num=%s#table-%s' % (int(num), table_number), number_in_table(num), attrs={'class':'num'})
                        t(html.td(link, attrs=attrs))
                    else:
                        t(html.td(u'&nbsp;'))
Exemplo n.º 7
0
def template_list_puzzle(p, ids):
    with p(html.ol()):
        for id in ids:
            p(html.li(html.a(ask_matrix.url(id), id)))
Exemplo n.º 8
0
def template_index(p, files):
    with p(html.ul()):
        for file in files:
            p(html.li(html.a(view_csv.url(file), file)))
Exemplo n.º 9
0
def template_originals(t, ticker, url, page):
    with t(html.div()):
        t(html.h1('Originals SEC Financials in 10K for %s' % ticker))
        t(u'Downloaded today from %s' % html.a(url, url))
    t(html.hr())
    t(unicode(page))
Exemplo n.º 10
0
def insert_anchors_into_html_at_indices(page, indices):
    for table_number,index in reversed(list(enumerate(indices))):
        attrs = {'name':'table-%s' % table_number}
        page = page[:index] + '\n' + html.a(attrs=attrs) + '\n' + page[index:]
    return page