X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=biaweb_db.py;fp=biaweb_db.py;h=1946ad7dafbe9f64a517105c8dbeec5b18585fd9;hp=9caad085f52a1f6ee4b6594020dd671c7aefb197;hb=5f4cc1e3f6bf2ffbf624dfc19d24c1b4eb2e15db;hpb=592798cba4152c0726edeb629da48cc8ac23a3a3 diff --git a/biaweb_db.py b/biaweb_db.py index 9caad08..1946ad7 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -4,6 +4,36 @@ import sqlite3 import os import os.path +import time + +# function to create an article +def create_article (dbname, title, summary, keywords, content, catid, stub, rating): + # time of creation + creattime = time.time () + modtime = creattime + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("INSERT INTO articles (title, summary, keywords, content, cdate, mdate, cid, stub, rating) \ + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);", (title, summary, keywords, content, creattime, + modtime, catid, stub, rating)) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False + +# function to delete an article +def delete_article (dbname, artid): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("DELETE FROM articles WHERE aid=?;", (artid,)) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False # function to get a category from the database def get_category (dbname, catid): @@ -44,6 +74,20 @@ def remove_category (dbname, catid): except sqlite3.Error: return False + +# function to create a category +def create_category (dbname, category_name, category_desc, category_stub): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);", + (category_name, category_desc, category_stub)) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False + # function to set the configuration and update the database def set_configuration (dbname, site_title, site_url, keywords, description, copyright, num_rss, dest_path): @@ -92,20 +136,6 @@ def get_configuration (dbname): except sqlite3.Error: return False - -# function to create a category -def create_category (dbname, category_name, category_desc, category_stub): - try: - conn = sqlite3.connect (dbname) - c = conn.cursor () - c.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);", - (category_name, category_desc, category_stub)) - conn.commit () - conn.close () - return True - 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: