<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

from tools import *
from utils import *

class DatabaseError(Exception):
    def __init__(self, content):
        Exception.__init__(self)

if os.path.exists("blog.db"):
    db = Connection("blog.db")
else:
    raise DatabaseError("Database file not found !")

def gat_page(id):
    page = db.get("SELECT * FROM pages WHERE id = ?", id)
    return page

def get_all_pages():
    pages = db.query("SELECT * FROM pages")
    return pages

def get_article(id):
    article = db.get("SELECT * FROM articles WHERE id = ?;", id)
    return article

def get_articles(page, post_per_page):
    articles = db.query("SELECT * FROM articles ORDER BY id DESC LIMIT ?, ?;",(page - 1) * 3, post_per_page)
    return articles

def get_all_articles():
    articles = db.query("SELECT * FROM articles ORDER BY id DESC;")
    return articles

def get_article_count():
    count = db.query('''SELECT COUNT(*) AS count FROM articles''')
    return count[0].count

def get_tag_articles(tag_name):
    sql = """SELECT * FROM articles AS a INNER JOIN tags AS t ON a.id = t.article_id WHERE t.name = ?;"""
    articles = db.query(sql, tag_name)<commit_msg>Get tag articles order by id<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

from tools import *
from utils import *

class DatabaseError(Exception):
    def __init__(self, content):
        Exception.__init__(self)

if os.path.exists("blog.db"):
    db = Connection("blog.db")
else:
    raise DatabaseError("Database file not found !")

def gat_page(id):
    page = db.get("SELECT * FROM pages WHERE id = ?", id)
    return page

def get_all_pages():
    pages = db.query("SELECT * FROM pages")
    return pages

def get_article(id):
    article = db.get("SELECT * FROM articles WHERE id = ?;", id)
    return article

def get_articles(page, post_per_page):
    articles = db.query("SELECT * FROM articles ORDER BY id DESC LIMIT ?, ?;",(page - 1) * 3, post_per_page)
    return articles

def get_all_articles():
    articles = db.query("SELECT * FROM articles ORDER BY id DESC;")
    return articles

def get_article_count():
    count = db.query('''SELECT COUNT(*) AS count FROM articles''')
    return count[0].count

def get_tag_articles(tag_name):
    sql = """SELECT * FROM articles AS a INNER JOIN tags AS t ON a.id = t.article_id WHERE t.name = ? ORDER BY id DESC;"""
    articles = db.query(sql, tag_name)
{'fraction_non_alphanumeric': 0.13104013104013104, 'fraction_numerical': 0.003276003276003276, 'mean_word_length': 3.5749063670411987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1738270', 'n_tokens_mistral': 796, 'n_tokens_neox': 779, 'n_words': 248}