X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=biaweb_db.py;fp=biaweb_db.py;h=2c8e6cdf3fae529c6ff91b6272f5c284a82ebde4;hp=576f2846b66d6b47c242b295a23c36de9078b2cb;hb=3632ca174c91a33db13178bc19ad2f93473b52c0;hpb=7db1961b4f7513f9ad5b6b357a655e16903e7f83 diff --git a/biaweb_db.py b/biaweb_db.py index 576f284..2c8e6cd 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -4,7 +4,55 @@ import sqlite3 import os import os.path -import pprint + +# function to set the configuration and update the database +def set_configuration (dbname, site_title, site_url, keywords, description, copyright, + num_rss, dest_path): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.executemany ("UPDATE config SET config_param=? WHERE config_name=?;", + [[site_url, "Website URL"], + [site_title, "Website Title"], + [keywords, "Keywords"], + [description, "Description"], + [num_rss, "No. of RSS items"], + [dest_path, "Destination path"], + [copyright, "Copyright"]]) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False + +# function to get the existing site configuration and return it as a tuple +def get_configuration (dbname): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("SELECT * FROM config;") + conn.commit () + recs = c.fetchall () + conn.close () + for name, param in recs: + if name == "Website URL": + website_url = param + elif name == "Website Title": + website_title = param + elif name == "Keywords": + keywords = param + elif name == "Description": + description = param + elif name == "No. of RSS items": + num_rss = int (param) + elif name == "Destination path": + destination = param + elif name == "Copyright": + copyright = param + return (website_url, website_title, keywords, description, num_rss, destination, copyright) + except sqlite3.Error: + return False + # function to create a category def create_category (dbname, category_name, category_desc, category_stub): @@ -30,6 +78,7 @@ def get_articles (dbname, category_id=None): c.execute ("SELECT * FROM articles WHERE cid=?", (category_id,)) conn.commit () rows = c.fetchall () + conn.close () return rows except sqlite3.Error: return False