X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=biaweb_db.py;fp=biaweb_db.py;h=576f2846b66d6b47c242b295a23c36de9078b2cb;hp=5496453c19904f8793046a377fff069f98925626;hb=7db1961b4f7513f9ad5b6b357a655e16903e7f83;hpb=ef16f33c036bee31ba27eb3bb6ec9486fcb23544 diff --git a/biaweb_db.py b/biaweb_db.py index 5496453..576f284 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -4,6 +4,7 @@ import sqlite3 import os import os.path +import pprint # function to create a category def create_category (dbname, category_name, category_desc, category_stub): @@ -18,6 +19,33 @@ def create_category (dbname, category_name, category_desc, category_stub): except sqlite3.Error: return False +# Function to get list of articles (either full list or just in a category +def get_articles (dbname, category_id=None): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + if category_id == None: + c.execute ("SELECT * FROM articles;") + else: + c.execute ("SELECT * FROM articles WHERE cid=?", (category_id,)) + conn.commit () + rows = c.fetchall () + return rows + except sqlite3.Error: + return False + +# Function to get list of categories and return a (category_id, category_name) array +def get_categories (dbname): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("SELECT * FROM categories;") + conn.commit () + recs = c.fetchall () + conn.close () + return recs + except sqlite3.Error: + return False # function to create a new site database def create_db (dbname, site_title, site_url, keywords, description, copyright,