Example #1
0
def test_asc():
    result = posts.get_posts(['tech'])
    assert_that(result).is_length(4)
    for i in range(len(result) - 1):
        assert_that(result[i]['id']).is_less_than_or_equal_to(result[i +
                                                                     1]['id'])
    print('ASCENDING SORT WORKS')
Example #2
0
def test_desc():
    result = posts.get_posts(['tech'], ascending=False)
    assert_that(result).is_length(4)
    for i in range(len(result) - 1):
        assert_that(result[i]['id']).is_greater_than_or_equal_to(
            result[i + 1]['id'])
    print('DESCENDING SORT WORKS')
Example #3
0
def test_basic():
    result = posts.get_posts(['sanity'])
    assert_that(result[0]).is_equal_to({
        'id': 100,
        'tags': ['sanity'],
        'reads': 100
    })
    print('BASIC PASSED - handler\'s being tested')
Example #4
0
def get_posts():
    requestdata, valid = validate_request(request)
    if not valid:
        return invalid_response(requestdata)
    theposts = posts.get_posts(tags=requestdata['tags'],
                               sortfield=requestdata['sortfield'],
                               ascending=(requestdata['direction'] == 'asc'))
    return post_response(theposts)
Example #5
0
def test_sortfield():
    sortfield = 'reads'
    result = posts.get_posts(['tech'], sortfield=sortfield)
    assert_that(result).is_length(4)
    for i in range(len(result) - 1):
        assert_that(result[i]['id']).is_less_than_or_equal_to(
            result[i + 1][sortfield])
    print('SORTBY WORKS')
Example #6
0
def channel(channel_name):
    list = posts.get_posts(channel_name)
    title = "/ch/" + channel_name
    if channels.is_channel(channel_name):
        return render_template("feed_layout.html",
                               channel_name=channel_name,
                               posts=list,
                               title=title)
    else:
        flash("Kanavaa " + channel_name + " ei ole olemassa")
        return redirect("/")
Example #7
0
File: app.py Project: xymostech/til
def main():
    if not is_logged_in():
        return redirect(url_for('login'))

    the_posts = posts.get_posts(get_logged_in_user())
    date_posts = posts.group_posts_by_date(the_posts)

    context = {
        'dates': sorted(date_posts.keys(), reverse=True),
        'date_posts': date_posts,
        'empty': len(the_posts) == 0
    }

    return render_template("main.html", **context)
Example #8
0
File: app.py Project: xymostech/til
def main():
    if not is_logged_in():
        return redirect(url_for('login'))

    the_posts = posts.get_posts(get_logged_in_user())
    date_posts = posts.group_posts_by_date(the_posts)

    context = {
        'dates': sorted(date_posts.keys(), reverse=True),
        'date_posts': date_posts,
        'empty': len(the_posts) == 0
    }

    return render_template("main.html", **context)
Example #9
0
def index():
    return render_template("index.html",
                           site_title="Lucas Blog - Softwareentwicklung",
                           og={
                               "title": "Lucas Blog - Softwareentwicklung",
                               "description": "Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi",
                               "image": url_for("static", filename="img/header.jpg"),
                               "url": "https://blog.lucas-hild.de",
                               "type": "blog"
                           },
                           seo_description="Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi",
                           header_title="Lucas Blog",
                           header_image=url_for("static", filename="img/header.jpg"),
                           posts=posts.get_posts())
Example #10
0
def atom_feed():
    feed = AtomFeed("Lucas Blog", feed_url="https://blog.lucas-hild.de/feed")

    for post in posts.get_posts():
        feed.add(title=post["title"],
                 title_type="text",
                 subtitle="Softwareentwicklung",
                 content=post["content"],
                 content_type="html",
                 summary=post["description"],
                 summary_type="text",
                 url="https://blog.lucas-hild.de/" + post["permalink"],
                 author="Lucas Hild",
                 published=post["date_time"],
                 updated=post["date_time"])

    return feed.get_response()
Example #11
0
def index():
    if check_user():
        if 'submitpost' in request.form:
            posts.make_post(
                request.form['title'],
                session['user'],
                request.form['content'])
        if 'submitcomment' in request.form:
            posts.make_comment(
                request.form['postid'],
                session['user'],
                request.form['content'])
        if 'deletepost' in request.form:
            posts.delete_post(request.form['postid'])
    return render_template(
        "home.html",
        posts = posts.get_posts(request.args.get('query')),
        user = session['user'],
        query = request.args.get('query'))
Example #12
0
def post_view(permalink):
    post_details = posts.get_post(permalink)

    if post_details:
        return render_template("post.html",
                               site_title=post_details["title"] + " | Lucas Blog",
                               og={
                                   "title": post_details["title"] + "| Lucas Blog",
                                   "description": post_details["description"],
                                   "image": "https://blog.lucas-hild.de" + post_details["image"],
                                   "url": "https://blog.lucas-hild.de" + "/" + permalink,
                                   "type": "article"
                               },
                               seo_description="Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi",
                               header_title=post_details["title"],
                               header_text=post_details["date"],
                               header_image=post_details["image"],
                               title=post_details["title"],
                               date=post_details["title"],
                               image=post_details["image"],
                               description=post_details["description"],
                               content=post_details["content"])
    else:
        return render_template("index.html",
                               site_title="404 | Lucas Blog",
                               og={
                                   "title": "Lucas Blog - Softwareentwicklung",
                                   "description": "Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi",
                                   "image": url_for("static", filename="img/404.jpg"),
                                   "url": "https://blog.lucas-hild.de",
                                   "type": "blog"
                               },
                               seo_description="Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi",
                               header_title="Seite nicht gefunden",
                               header_image=url_for("static", filename="img/404.jpg"),
                               posts=posts.get_posts()), 404
Example #13
0
def progress(request):
    commits = get_commits()
    posts = get_posts()
    return direct_to_template(request, 'progress/progress.html', {"posts":posts, "commits":commits})
Example #14
0
def index():
    list = posts.get_posts("")
    return render_template("feed_layout.html",
                           posts=list,
                           channel_name="main",
                           title="Etusivu")
Example #15
0
def index():
    return render_template('index.html',
                           posts=posts.get_posts(),
                           tags=posts.header_tags())
Example #16
0
    'regex': re.compile(common_re.format('logos', '.*', 'logos'), re.DOTALL),
    'replace': common_re.format('logos', '\n {} \n', 'logos')
}

pcts_re = {
    'regex': re.compile(common_re.format('pcts', '.*', 'pcts'), re.DOTALL),
    'replace': common_re.format('pcts', '\n {} \n', 'pcts')
}

REGEXES = [post_eng_re, post_ptbr_re, logos_re, pcts_re]

if __name__ == "__main__":
    readme = root / "README.md"

    # Retrieve most recent posts for each language
    posts = get_posts(2)

    post_eng_re['replace'] = post_eng_re['replace'].format('\n\n '.join(
        posts['eng']))
    post_ptbr_re['replace'] = post_ptbr_re['replace'].format('\n\n '.join(
        posts['pt-br']))

    # Retrieve profile overview
    repositories = get_repos()
    languages = get_languages(repositories)
    percentages = calculate_languages(languages)
    html = languages_to_html(percentages, n=8)

    logos_re['replace'] = logos_re['replace'].format('\n'.join(html['logos']))
    pcts_re['replace'] = pcts_re['replace'].format('\n'.join(html['pcts']))
Example #17
0
def api_posts():
    return jsonify(posts.get_posts())
Example #18
0
                active_user = None
                break

    elif active_user.role == 'admin':
        ANS2 = ['1', '2']

        while ans not in ANS2 and ans != '2':
            print(f'possible actions:')
            ans = input('1. See user list \n2. Sign out\nplease choose :')

            if ans == '1':
                for el in population.keys():
                    user = population[el]
                    print(
                        f'\n{user.u_name} registration date is {user.reg_date}'
                    )

                    if get_posts(el) == 'No posts yet':
                        print(f'{user.u_name} have no posts yet')
                    else:
                        for post in user.posts:
                            print(
                                f'user {user.u_name} posted {post[0]} in {post[2]}'
                            )

            elif ans == '2':
                active_user = None
                break

            ans = None
Example #19
0
def test_multipletags_uniqueness():
    results = posts.get_posts(['tech', 'history'])
    ids = [post['id'] for post in results]
    # sets have no duplicate elements
    assert_that(ids).is_length(len(set(ids)))
    print('UNIQUENESS WORKS')
Example #20
0
def test_multipletags_disjoint():
    techresults = posts.get_posts(['tech'])
    disjointresults = posts.get_posts(['sanity'])
    bothresults = posts.get_posts(['tech', 'sanity'])
    assert_that(bothresults).is_length(len(techresults) + len(disjointresults))
    print('MULTIPLE TAG RETRIEVAL IS SANE!')