1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Database handling functions
8 # function to set the configuration and update the database
9 def set_configuration (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
12 conn
= sqlite3
.connect (dbname
)
14 c
.executemany ("UPDATE config SET config_param=? WHERE config_name=?;",
15 [[site_url
, "Website URL"],
16 [site_title
, "Website Title"],
17 [keywords
, "Keywords"],
18 [description
, "Description"],
19 [num_rss
, "No. of RSS items"],
20 [dest_path
, "Destination path"],
21 [copyright
, "Copyright"]])
28 # function to get the existing site configuration and return it as a tuple
29 def get_configuration (dbname
):
31 conn
= sqlite3
.connect (dbname
)
33 c
.execute ("SELECT * FROM config;")
37 for name
, param
in recs
:
38 if name
== "Website URL":
40 elif name
== "Website Title":
42 elif name
== "Keywords":
44 elif name
== "Description":
46 elif name
== "No. of RSS items":
48 elif name
== "Destination path":
50 elif name
== "Copyright":
52 return (website_url
, website_title
, keywords
, description
, num_rss
, destination
, copyright
)
57 # function to create a category
58 def create_category (dbname
, category_name
, category_desc
, category_stub
):
60 conn
= sqlite3
.connect (dbname
)
62 c
.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);",
63 (category_name
, category_desc
, category_stub
))
70 # Function to get list of articles (either full list or just in a category
71 def get_articles (dbname
, category_id
=None):
73 conn
= sqlite3
.connect (dbname
)
75 if category_id
== None:
76 c
.execute ("SELECT * FROM articles;")
78 c
.execute ("SELECT * FROM articles WHERE cid=?", (category_id
,))
86 # Function to get list of categories and return a (category_id, category_name) array
87 def get_categories (dbname
):
89 conn
= sqlite3
.connect (dbname
)
91 c
.execute ("SELECT * FROM categories;")
99 # function to create a new site database
100 def create_db (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
103 if os
.path
.exists (dbname
):
109 conn
= sqlite3
.connect (dbname
)
111 c
.execute ("CREATE TABLE IF NOT EXISTS \
112 categories (cid INTEGER PRIMARY KEY, \
113 name TEXT, desc TEXT, \
115 c
.execute ("CREATE TABLE IF NOT EXISTS \
116 articles (aid INTEGER PRIMARY KEY, \
117 title TEXT, summary TEXT, keywords TEXT, \
118 content TEXT, cdate NUMERIC, mdate NUMERIC, cid NUMERIC, \
119 stub TEXT, rating NUMERIC);")
120 c
.execute ("CREATE TABLE IF NOT EXISTS \
121 config (config_name TEXT, config_param TEXT);")
123 c
.execute ("CREATE TABLE IF NOT EXISTS \
124 templates (template_name TEXT, template_content);")
126 template_main
= """<?xml version="1.0" encoding="UTF-8"?>
127 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
128 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
130 <title>${site_title}</title>
131 <base href="${site_url}" />
132 <meta name="generator" content="BiaWeb"/>
133 <meta name="keywords" content="${meta_keywords}"/>
134 <meta name="description" content="${meta_description}"/>
135 <link rel="StyleSheet" type="text/css" href="style.css" />
136 <link rel="alternate" type="application/rss+xml" title="Entries RSS 2.0" href="subscribe.xml" />
140 <h1><a href="${site_url}">${page_title}</a></h1>
141 <div class="headerdesc">${page_desc}</div>
148 ${list_of_categories}
152 <a href="subscribe.xml">Latest articles (RSS)</a>
154 <form action="cgi-bin/search.py" method="post" enctype="multipart/form-data">
155 <p><input type="text" name="query" maxlength="255" style="width:142px;border: 1px inset #5A5A5A; color:#5A5A5A; background-color:#FFFFFF;" value="" /><br />
156 <input type="submit" value="Search" /><br />
157 <input type="hidden" name="fromsearch" value="fromsearch" />
158 <input type="radio" name="criteria" value="1" checked="checked" />All words<br />
159 <input type="radio" name="criteria" value="2" />Any word</p>
162 <div id="footer">${copyright}<br />Site generated by
163 <a href=\"http://harishankar.org/software/biaweb.php\">BiaWeb</a> created by V. Harishankar</div>
167 template_article_bit
= """<h2>${article_title}</h2>
168 <div class="modified">Created: ${article_cdate} | Last modified: ${article_mdate}</div>
169 <div class="rating">Rating: ${rating}</div>
170 <div class="content">${article_contents}</div>
173 template_news_item_bit
= """<h3><a href="${news_link}">${news_title}</a></h3>
174 <div class="modified">${news_datetime}</div>
175 <div class="content">${news_description}</div>
178 template_index_bit
= """<h2>Welcome to ${site_name}</h2>
179 <div class="content">
180 Welcome to my site, ${site_name}.
182 <h2>Latest Articles</h2>
186 template_table_bit
= """<h2>${category_title}</h2>
187 <p>${category_desc}</p>
188 <table class="categorytable">
191 <td style="width:50%">Title</td>
202 template_tablerow_bit
= """<tr>
203 <td style="width:50%"><a href="${article_url}">${title}</a></td>
209 template_style
= """body {
210 font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif;
212 background-color: #ffffff;
218 background-color: #efefef;
242 background-color: #efefef;
246 font-variant: small-caps;
259 .categorytable thead {
274 font-family: "Bitstream Vera Serif", Serif;
283 border-bottom: 1px solid;
284 border-color: #888888;
292 h1 a, h1 a:hover, h1 a:visited, h2 a:active {
293 text-decoration: none;
297 background-color: #efefef;
299 h2 a, h2 a:hover, h2 a:visited, h2 a:active {
300 text-decoration: none;
314 c
.executemany ("INSERT INTO templates (template_name, template_content) VALUES (?, ?);",
315 [["main_template", template_main
],
316 ["article_bit", template_article_bit
],
317 ["news_bit", template_news_item_bit
],
318 ["table_bit", template_table_bit
],
319 ["tablerow_bit", template_tablerow_bit
],
320 ["stylesheet", template_style
],
321 ["index_bit", template_index_bit
]])
323 c
.executemany ("INSERT INTO config (config_name, config_param) VALUES (?, ?); ",
324 [["Website URL", site_url
],
325 ["Website Title", site_title
],
326 ["Keywords", keywords
],
327 ["Description", description
],
328 ["No. of RSS items", num_rss
],
329 ["Destination path", dest_path
],
330 ["Copyright", copyright
]])
335 except sqlite3
.Error
: