1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Database handling functions
9 # function to create a category
10 def create_category (dbname
, category_name
, category_desc
, category_stub
):
12 conn
= sqlite3
.connect (dbname
)
14 c
.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);",
15 (category_name
, category_desc
, category_stub
))
22 # Function to get list of articles (either full list or just in a category
23 def get_articles (dbname
, category_id
=None):
25 conn
= sqlite3
.connect (dbname
)
27 if category_id
== None:
28 c
.execute ("SELECT * FROM articles;")
30 c
.execute ("SELECT * FROM articles WHERE cid=?", (category_id
,))
37 # Function to get list of categories and return a (category_id, category_name) array
38 def get_categories (dbname
):
40 conn
= sqlite3
.connect (dbname
)
42 c
.execute ("SELECT * FROM categories;")
50 # function to create a new site database
51 def create_db (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
54 if os
.path
.exists (dbname
):
60 conn
= sqlite3
.connect (dbname
)
62 c
.execute ("CREATE TABLE IF NOT EXISTS \
63 categories (cid INTEGER PRIMARY KEY, \
64 name TEXT, desc TEXT, \
66 c
.execute ("CREATE TABLE IF NOT EXISTS \
67 articles (aid INTEGER PRIMARY KEY, \
68 title TEXT, summary TEXT, keywords TEXT, \
69 content TEXT, cdate NUMERIC, mdate NUMERIC, cid NUMERIC, \
70 stub TEXT, rating NUMERIC);")
71 c
.execute ("CREATE TABLE IF NOT EXISTS \
72 config (config_name TEXT, config_param TEXT);")
74 c
.execute ("CREATE TABLE IF NOT EXISTS \
75 templates (template_name TEXT, template_content);")
77 template_main
= """<?xml version="1.0" encoding="UTF-8"?>
78 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
79 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
81 <title>${site_title}</title>
82 <base href="${site_url}" />
83 <meta name="generator" content="BiaWeb"/>
84 <meta name="keywords" content="${meta_keywords}"/>
85 <meta name="description" content="${meta_description}"/>
86 <link rel="StyleSheet" type="text/css" href="style.css" />
87 <link rel="alternate" type="application/rss+xml" title="Entries RSS 2.0" href="subscribe.xml" />
91 <h1><a href="${site_url}">${page_title}</a></h1>
92 <div class="headerdesc">${page_desc}</div>
103 <a href="subscribe.xml">Latest articles (RSS)</a>
105 <form action="cgi-bin/search.py" method="post" enctype="multipart/form-data">
106 <p><input type="text" name="query" maxlength="255" style="width:142px;border: 1px inset #5A5A5A; color:#5A5A5A; background-color:#FFFFFF;" value="" /><br />
107 <input type="submit" value="Search" /><br />
108 <input type="hidden" name="fromsearch" value="fromsearch" />
109 <input type="radio" name="criteria" value="1" checked="checked" />All words<br />
110 <input type="radio" name="criteria" value="2" />Any word</p>
113 <div id="footer">${copyright}<br />Site generated by
114 <a href=\"http://harishankar.org/software/biaweb.php\">BiaWeb</a> created by V. Harishankar</div>
118 template_article_bit
= """<h2>${article_title}</h2>
119 <div class="modified">Created: ${article_cdate} | Last modified: ${article_mdate}</div>
120 <div class="rating">Rating: ${rating}</div>
121 <div class="content">${article_contents}</div>
124 template_news_item_bit
= """<h3><a href="${news_link}">${news_title}</a></h3>
125 <div class="modified">${news_datetime}</div>
126 <div class="content">${news_description}</div>
129 template_index_bit
= """<h2>Welcome to ${site_name}</h2>
130 <div class="content">
131 Welcome to my site, ${site_name}.
133 <h2>Latest Articles</h2>
137 template_table_bit
= """<h2>${category_title}</h2>
138 <p>${category_desc}</p>
139 <table class="categorytable">
142 <td style="width:50%">Title</td>
153 template_tablerow_bit
= """<tr>
154 <td style="width:50%"><a href="${article_url}">${title}</a></td>
160 template_style
= """body {
161 font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif;
163 background-color: #ffffff;
169 background-color: #efefef;
193 background-color: #efefef;
197 font-variant: small-caps;
210 .categorytable thead {
225 font-family: "Bitstream Vera Serif", Serif;
234 border-bottom: 1px solid;
235 border-color: #888888;
243 h1 a, h1 a:hover, h1 a:visited, h2 a:active {
244 text-decoration: none;
248 background-color: #efefef;
250 h2 a, h2 a:hover, h2 a:visited, h2 a:active {
251 text-decoration: none;
265 c
.executemany ("INSERT INTO templates (template_name, template_content) VALUES (?, ?);",
266 [["main_template", template_main
],
267 ["article_bit", template_article_bit
],
268 ["news_bit", template_news_item_bit
],
269 ["table_bit", template_table_bit
],
270 ["tablerow_bit", template_tablerow_bit
],
271 ["stylesheet", template_style
],
272 ["index_bit", template_index_bit
]])
274 c
.executemany ("INSERT INTO config (config_name, config_param) VALUES (?, ?); ",
275 [["Website URL", site_url
],
276 ["Website Title", site_title
],
277 ["Keywords", keywords
],
278 ["Description", description
],
279 ["No. of RSS items", num_rss
],
280 ["Destination path", dest_path
],
281 ["Copyright", copyright
]])
286 except sqlite3
.Error
: