예제 #1
0
def post(slug, year, month, day=None):
    posts, total_posts, total_pages = helpers.get_formatted_posts(slugs=[slug])

    if not day and posts:
        pubdate = dateutil.parser.parse(posts[0]['date_gmt'])
        day = pubdate.strftime('%d')
        return flask.redirect(
            '/{year}/{month}/{day}/{slug}'.format(**locals())
        )

    if not posts:
        flask.abort(404)

    post = posts[0]

    topics = api.get_topics(post_id=post['id'])

    if topics:
        post['topic'] = topics[0]

    tags = api.get_tags(post_id=post['id'])
    related_posts, total_posts, total_pages = helpers.get_formatted_posts(
        tag_ids=[tag['id'] for tag in tags],
        per_page=3,
        exclude=post['id']
    )

    return flask.render_template(
        'post.html',
        post=post,
        tags=tags,
        related_posts=related_posts,
    )
예제 #2
0
def post(slug, year=None, month=None, day=None):
    posts, total_posts, total_pages = helpers.get_formatted_posts(slugs=[slug])

    if not posts:
        flask.abort(404)

    post = posts[0]

    topics = api.get_topics(post_id=post['id'])

    if topics:
        post['topic'] = topics[0]

    tags = api.get_tags(post_id=post['id'])
    related_posts, total_posts, total_pages = helpers.get_formatted_posts(
        tag_ids=[tag['id'] for tag in tags],
        per_page=3
    )

    return flask.render_template(
        'post.html',
        post=post,
        tags=tags,
        related_posts=related_posts,
    )
예제 #3
0
def post(slug, year=None, month=None, day=None):
    posts, total_posts, total_pages = helpers.get_formatted_posts(slugs=[slug])

    if not posts:
        flask.abort(404)

    if not (day and month and year):
        pubdate = dateutil.parser.parse(posts[0]["date_gmt"])
        day = pubdate.strftime("%d")
        month = pubdate.strftime("%m")
        year = pubdate.strftime("%Y")

        return flask.redirect(
            "/{year}/{month}/{day}/{slug}".format(**locals())
        )

    post = posts[0]

    topics = api.get_topics(post_id=post["id"])

    if topics:
        post["topic"] = topics[0]

    tags = api.get_tags(post_id=post["id"])
    related_posts, total_posts, total_pages = helpers.get_formatted_posts(
        tag_ids=[tag["id"] for tag in tags], per_page=3, exclude=post["id"]
    )

    # Even though we're filtering tags below, we need to know the snapcraft.io
    # tag, specifically to add the canonical meta tag
    snapcraft_io_tag = list(filter(lambda tag: tag["id"] == 2996, tags))
    if snapcraft_io_tag:
        canonical_link = "https://snapcraft.io/blog/" + slug
    else:
        canonical_link = None

    display_tags = helpers.filter_tags_for_display(tags)

    return flask.render_template(
        "post.html",
        post=post,
        tags=display_tags,
        related_posts=related_posts,
        canonical_link=canonical_link,
    )
예제 #4
0
def post(slug, year, month, day=None):
    posts, total_posts, total_pages = helpers.get_formatted_posts(slugs=[slug])

    if not day and posts:
        pubdate = dateutil.parser.parse(posts[0]['date_gmt'])
        day = pubdate.strftime('%d')
        return flask.redirect(
            '/{year}/{month}/{day}/{slug}'.format(**locals()))

    if not posts:
        flask.abort(404)

    post = posts[0]

    topics = api.get_topics(post_id=post['id'])

    if topics:
        post['topic'] = topics[0]

    tags = api.get_tags(post_id=post['id'])
    related_posts, total_posts, total_pages = helpers.get_formatted_posts(
        tag_ids=[tag['id'] for tag in tags], per_page=3, exclude=post['id'])

    snapcraft_io_tag = list(filter(lambda tag: tag['id'] == 2996, tags))

    if snapcraft_io_tag:
        canonical_link = 'https://snapcraft.io/blog/' + slug
    else:
        canonical_link = None

    return flask.render_template(
        'post.html',
        post=post,
        tags=tags,
        related_posts=related_posts,
        canonical_link=canonical_link,
    )
예제 #5
0
commands_topic = api.get_commands_topic()

# imageSelect = types.ReplyKeyboardMarkup(one_time_keyboard=True)  # create the image selection keyboard
# imageSelect.add('c**k', 'pussy','mv','cd')
imageSelect = types.ReplyKeyboardMarkup()
imageSelect.add("A")
imageSelect.add("B")
imageSelect.add("C")
imageSelect.add("D")

hideBoard = types.ReplyKeyboardRemove(
)  # if sent as reply_markup, will hide the keyboard

command = ['start']
command_topics = api.get_topics()
list_quetions_by_topic = []
globals()['list_quetions_by_topic'] = []
len_list = 0

# error handling if user isn't known yet
# (obsolete once known users are saved to file, because all users
#   had to use the /start command and are therefore known to the bot)
mv = "\t Feedback \n A : Phản hồi \n B : Người đại diện \n C : Nhàm chán \n D : Vcl"


def get_user_step(uid):
    if uid in userStep:
        return userStep[uid]
    else:
        knownUsers.append(uid)