<commit_before>from . import db_cursor, db


def get_post_list(count=10, start=-1):  # generator
    """Yeild a list of posts

    :returns: generator(post, [post...])
    """
    if start == -1:
        start = db_cursor.execute("SELECT MAX(eid) FROM posts").fetchone()[0]
    if start == 0:
        return  # no posts in database
    for post in db_cursor.execute(
            """SELECT * FROM posts WHERE eid <= ? ORDER BY eid DESC LIMIT ?""",
            (start, count)):
        yield dict(zip(('eid', 'title', 'post', 'post_source'), post))


def get_reverse_post_list(count=10, start=0):  # generator
    """Yield a list of posts, starting from oldest

    :returns: generator(post, [post...])
    """
    for post in db_cursor.execute(
            """SELECT * FROM posts WHERE eid >= ? ORDER BY eid ASC LIMIT ?""",
            (start, count)):
        yield dict(zip(('eid', 'title', 'post', 'post_source'), post))


def get_post(eid):
    return dict(
        zip(('eid', 'title', 'post'), db_cursor.execute(
            """SELECT * FROM posts WHERE eid = ?""", (eid,))))


def add_post(request):
    """Add a post to posts table

    :returns: int:new_post_eid
    """
    post = request.values.to_dict()
    db_cursor.execute("""
        INSERT INTO posts (title, post, post_source)
        VALUES (?,?, ?)
        """, (post['title'], post['post'], post['post_source']))
    db.commit()
    return db_cursor.execute("SELECT COUNT(*) FROM posts").fetchone()[0]


def update_post(eid, request):
    post = request.values.to_dict()
    db_cursor.execute("""
        UPDATE posts
        SET
            title=?,
            post=?,
            post_source=?
        WHERE eid=?
        """, (post['title'], post['post'], post['post_source'], eid))
    return eid


def delete_post(eid):
    db_cursor.execute("""DELETE FROM posts WHERE eid = ?""", (eid, ))
    return eid
<commit_msg>lib/blag/util.py: commit to database after editing<commit_after>from . import db_cursor, db


def get_post_list(count=10, start=-1):  # generator
    """Yeild a list of posts

    :returns: generator(post, [post...])
    """
    if start == -1:
        start = db_cursor.execute("SELECT MAX(eid) FROM posts").fetchone()[0]
    if start == 0:
        return  # no posts in database
    for post in db_cursor.execute(
            """SELECT * FROM posts WHERE eid <= ? ORDER BY eid DESC LIMIT ?""",
            (start, count)):
        yield dict(zip(('eid', 'title', 'post', 'post_source'), post))


def get_reverse_post_list(count=10, start=0):  # generator
    """Yield a list of posts, starting from oldest

    :returns: generator(post, [post...])
    """
    for post in db_cursor.execute(
            """SELECT * FROM posts WHERE eid >= ? ORDER BY eid ASC LIMIT ?""",
            (start, count)):
        yield dict(zip(('eid', 'title', 'post', 'post_source'), post))


def get_post(eid):
    return dict(
        zip(('eid', 'title', 'post'), db_cursor.execute(
            """SELECT * FROM posts WHERE eid = ?""", (eid,))))


def add_post(request):
    """Add a post to posts table

    :returns: int:new_post_eid
    """
    post = request.values.to_dict()
    db_cursor.execute("""
        INSERT INTO posts (title, post, post_source)
        VALUES (?,?, ?)
        """, (post['title'], post['post'], post['post_source']))
    db.commit()
    return db_cursor.execute("SELECT COUNT(*) FROM posts").fetchone()[0]


def update_post(eid, request):
    post = request.values.to_dict()
    db_cursor.execute("""
        UPDATE posts
        SET
            title=?,
            post=?,
            post_source=?
        WHERE eid=?
        """, (post['title'], post['post'], post['post_source'], eid))
    db.commit()
    return eid


def delete_post(eid):
    db_cursor.execute("""DELETE FROM posts WHERE eid = ?""", (eid, ))
    return eid

{'fraction_non_alphanumeric': 0.1664495962490232, 'fraction_numerical': 0.005209690023443605, 'mean_word_length': 2.639810426540284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3168814', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1215, 'n_words': 334}