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):
c.execute ("SELECT * FROM articles WHERE cid=?", (category_id,))
conn.commit ()
rows = c.fetchall ()
+ conn.close ()
return rows
except sqlite3.Error:
return False