1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Database handling functions
8 # function to get a category from the database
9 def get_category (dbname
, catid
):
11 conn
= sqlite3
.connect (dbname
)
13 c
.execute ("SELECT * FROM categories WHERE cid=?", (catid
,))
21 # function to update a category
22 def update_category (dbname
, catid
, cat_name
, cat_desc
, cat_stub
):
24 conn
= sqlite3
.connect (dbname
)
26 c
.execute ("UPDATE categories SET name=?, desc=?, stub=? WHERE cid=?;",
27 (cat_name
, cat_desc
, cat_stub
, catid
))
34 # function to set the configuration and update the database
35 def set_configuration (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
38 conn
= sqlite3
.connect (dbname
)
40 c
.executemany ("UPDATE config SET config_param=? WHERE config_name=?;",
41 [[site_url
, "Website URL"],
42 [site_title
, "Website Title"],
43 [keywords
, "Keywords"],
44 [description
, "Description"],
45 [num_rss
, "No. of RSS items"],
46 [dest_path
, "Destination path"],
47 [copyright
, "Copyright"]])
54 # function to get the existing site configuration and return it as a tuple
55 def get_configuration (dbname
):
57 conn
= sqlite3
.connect (dbname
)
59 c
.execute ("SELECT * FROM config;")
63 for name
, param
in recs
:
64 if name
== "Website URL":
66 elif name
== "Website Title":
68 elif name
== "Keywords":
70 elif name
== "Description":
72 elif name
== "No. of RSS items":
74 elif name
== "Destination path":
76 elif name
== "Copyright":
78 return (website_url
, website_title
, keywords
, description
, num_rss
, destination
, copyright
)
83 # function to create a category
84 def create_category (dbname
, category_name
, category_desc
, category_stub
):
86 conn
= sqlite3
.connect (dbname
)
88 c
.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);",
89 (category_name
, category_desc
, category_stub
))
96 # Function to get list of articles (either full list or just in a category
97 def get_articles (dbname
, category_id
=None):
99 conn
= sqlite3
.connect (dbname
)
101 if category_id
== None:
102 c
.execute ("SELECT * FROM articles;")
104 c
.execute ("SELECT * FROM articles WHERE cid=?", (category_id
,))
109 except sqlite3
.Error
:
112 # Function to get list of categories and return a (category_id, category_name) array
113 def get_categories (dbname
):
115 conn
= sqlite3
.connect (dbname
)
117 c
.execute ("SELECT * FROM categories;")
122 except sqlite3
.Error
:
125 # function to create a new site database
126 def create_db (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
129 if os
.path
.exists (dbname
):
135 conn
= sqlite3
.connect (dbname
)
137 c
.execute ("CREATE TABLE IF NOT EXISTS \
138 categories (cid INTEGER PRIMARY KEY, \
139 name TEXT, desc TEXT, \
141 c
.execute ("CREATE TABLE IF NOT EXISTS \
142 articles (aid INTEGER PRIMARY KEY, \
143 title TEXT, summary TEXT, keywords TEXT, \
144 content TEXT, cdate NUMERIC, mdate NUMERIC, cid NUMERIC, \
145 stub TEXT, rating NUMERIC);")
146 c
.execute ("CREATE TABLE IF NOT EXISTS \
147 config (config_name TEXT, config_param TEXT);")
149 c
.execute ("CREATE TABLE IF NOT EXISTS \
150 templates (template_name TEXT, template_content);")
152 template_main
= """<?xml version="1.0" encoding="UTF-8"?>
153 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
154 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
156 <title>${site_title}</title>
157 <base href="${site_url}" />
158 <meta name="generator" content="BiaWeb"/>
159 <meta name="keywords" content="${meta_keywords}"/>
160 <meta name="description" content="${meta_description}"/>
161 <link rel="StyleSheet" type="text/css" href="style.css" />
162 <link rel="alternate" type="application/rss+xml" title="Entries RSS 2.0" href="subscribe.xml" />
166 <h1><a href="${site_url}">${page_title}</a></h1>
167 <div class="headerdesc">${page_desc}</div>
174 ${list_of_categories}
178 <a href="subscribe.xml">Latest articles (RSS)</a>
180 <form action="cgi-bin/search.py" method="post" enctype="multipart/form-data">
181 <p><input type="text" name="query" maxlength="255" style="width:142px;border: 1px inset #5A5A5A; color:#5A5A5A; background-color:#FFFFFF;" value="" /><br />
182 <input type="submit" value="Search" /><br />
183 <input type="hidden" name="fromsearch" value="fromsearch" />
184 <input type="radio" name="criteria" value="1" checked="checked" />All words<br />
185 <input type="radio" name="criteria" value="2" />Any word</p>
188 <div id="footer">${copyright}<br />Site generated by
189 <a href=\"http://harishankar.org/software/biaweb.php\">BiaWeb</a> created by V. Harishankar</div>
193 template_article_bit
= """<h2>${article_title}</h2>
194 <div class="modified">Created: ${article_cdate} | Last modified: ${article_mdate}</div>
195 <div class="rating">Rating: ${rating}</div>
196 <div class="content">${article_contents}</div>
199 template_news_item_bit
= """<h3><a href="${news_link}">${news_title}</a></h3>
200 <div class="modified">${news_datetime}</div>
201 <div class="content">${news_description}</div>
204 template_index_bit
= """<h2>Welcome to ${site_name}</h2>
205 <div class="content">
206 Welcome to my site, ${site_name}.
208 <h2>Latest Articles</h2>
212 template_table_bit
= """<h2>${category_title}</h2>
213 <p>${category_desc}</p>
214 <table class="categorytable">
217 <td style="width:50%">Title</td>
228 template_tablerow_bit
= """<tr>
229 <td style="width:50%"><a href="${article_url}">${title}</a></td>
235 template_style
= """body {
236 font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif;
238 background-color: #ffffff;
244 background-color: #efefef;
268 background-color: #efefef;
272 font-variant: small-caps;
285 .categorytable thead {
300 font-family: "Bitstream Vera Serif", Serif;
309 border-bottom: 1px solid;
310 border-color: #888888;
318 h1 a, h1 a:hover, h1 a:visited, h2 a:active {
319 text-decoration: none;
323 background-color: #efefef;
325 h2 a, h2 a:hover, h2 a:visited, h2 a:active {
326 text-decoration: none;
340 c
.executemany ("INSERT INTO templates (template_name, template_content) VALUES (?, ?);",
341 [["main_template", template_main
],
342 ["article_bit", template_article_bit
],
343 ["news_bit", template_news_item_bit
],
344 ["table_bit", template_table_bit
],
345 ["tablerow_bit", template_tablerow_bit
],
346 ["stylesheet", template_style
],
347 ["index_bit", template_index_bit
]])
349 c
.executemany ("INSERT INTO config (config_name, config_param) VALUES (?, ?); ",
350 [["Website URL", site_url
],
351 ["Website Title", site_title
],
352 ["Keywords", keywords
],
353 ["Description", description
],
354 ["No. of RSS items", num_rss
],
355 ["Destination path", dest_path
],
356 ["Copyright", copyright
]])
361 except sqlite3
.Error
: