예제 #1
0
def show_entries():
    """ The main view: presents author info and entries. """
    entries = []
    cur = g.db.execute("SELECT location " + "FROM entries " +
                       "ORDER BY published DESC")
    for (row, ) in cur.fetchall():
        if os.path.exists(row + ".md"):
            entries.append(file_parser(row + ".md"))
    try:
        entries = entries[:10]
    except IndexError:
        entries = None

    before = 1

    for entry in entries:
        for i in entry['syndication'].split(','):
            if i.startswith('https://twitter.com/'):
                twitter = dict()
                vals = i.split('/')
                twitter['id'] = vals[len(vals) - 1]
                twitter['link'] = i
                entry['twitter'] = twitter
                break

    return render_template('blog_entries.html', entries=entries, before=before)
예제 #2
0
def profile(year, month, day, name):
    """ Get a specific article """
    # try:
    file_name = "data/{year}/{month}/{day}/{name}".format(year=year,
                                                          month=month,
                                                          day=day,
                                                          name=name)
    entry = file_parser(file_name + ".md")

    if os.path.exists(file_name + ".jpg"):
        entry['photo'] = file_name + ".jpg"  # get the actual file
    if os.path.exists(file_name + ".mp4"):
        entry['video'] = file_name + ".mp4"  # get the actual file
    if os.path.exists(file_name + ".mp3"):
        entry['audio'] = file_name + ".mp3"  # get the actual file

    mentions = get_mentions('http://' + DOMAIN_NAME +
                            '/e/{year}/{month}/{day}/{name}'.format(
                                year=year, month=month, day=day, name=name))

    reply_to = []  # where we store our replies so we can fetch their info
    for i in entry['in_reply_to']:  # for all the replies we have...
        if type(i) == dict:  # which are not images on our site...
            reply_to.append(i)
        elif i.startswith('http://127.0.0.1:5000'):
            reply_to.append(
                file_parser(
                    i.replace('http://127.0.0.1:5000/e/', 'data/', 1) + ".md"))
        elif i.startswith(
                'http'):  # which are not data resources on our site...
            reply_to.append(get_entry_content(i))

    for i in entry['syndication'].split(','):
        if i.startswith(
                'https://twitter.com/'):  # if there's twitter syndication
            twitter = dict()
            vals = i.split('/')
            twitter['id'] = vals[len(vals) - 1]
            twitter['link'] = i
            entry['twitter'] = twitter
        if i.startswith('https://www.facebook.com/'):
            entry['facebook'] = {'link': i}

    return render_template('entry.html',
                           entry=entry,
                           mentions=mentions,
                           reply_to=reply_to)
예제 #3
0
def time_search_year(year):
    """ Gets all entries posted during a specific year """
    entries = []
    cur = g.db.execute("""
        SELECT entries.location FROM entries
        WHERE CAST(strftime('%Y',entries.published)AS INT) = {year}
        ORDER BY entries.published DESC
        """.format(year=int(year)))

    for (row, ) in cur.fetchall():
        if os.path.exists(row + ".md"):
            entries.append(file_parser(row + ".md"))
    return render_template('blog_entries.html', entries=entries)
예제 #4
0
def time_search(year, month, day):
    """ Gets all notes posted on a specific day """
    entries = []
    cur = g.db.execute("""
        SELECT entries.location FROM entries
        WHERE CAST(strftime('%Y',entries.published)AS INT) = {year}
        AND CAST(strftime('%m',entries.published)AS INT) = {month}
        AND CAST(strftime('%d',entries.published)AS INT) = {day}
        ORDER BY entries.published DESC
        """.format(year=int(year), month=int(month), day=int(day)))

    for (row, ) in cur.fetchall():
        if os.path.exists(row + ".md"):
            entries.append(file_parser(row + ".md"))
    return render_template('blog_entries.html', entries=entries)
예제 #5
0
def tag_search(category):
    """ Get all entries with a specific tag """
    entries = []
    cur = g.db.execute("""
         SELECT entries.location FROM categories
         INNER JOIN entries ON
         entries.slug = categories.slug AND
         entries.published = categories.published
         WHERE categories.category='{category}'
         ORDER BY entries.published DESC
        """.format(category=category))
    for (row, ) in cur.fetchall():
        if os.path.exists(row + ".md"):
            entries.append(file_parser(row + ".md"))
    return render_template('blog_entries.html', entries=entries)
예제 #6
0
def pagination(number):
    entries = []
    cur = g.db.execute("""
        SELECT entries.location FROM entries
        ORDER BY entries.published DESC
        """.format(datetime=datetime))

    for (row, ) in cur.fetchall():
        if os.path.exists(row + ".md"):
            entries.append(file_parser(row + ".md"))

    try:
        start = int(number) * 10
        entries = entries[start:start + 10]
    except IndexError:
        entries = None

    before = int(number) + 1

    return render_template('blog_entries.html', entries=entries, before=before)