From 6ba107bc3e5bef66a447978048e6c41ed038e969 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Wed, 1 Dec 2010 15:37:34 +0530 Subject: [PATCH] Implemented the RSS feed exporter RSS feed exporter is now implemented. This completes the main feature set of the BiaWeb Qt application. This is probably beta 1 --- biaweb_exporter.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ biaweb_strings.py | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/biaweb_exporter.py b/biaweb_exporter.py index 47ccead..9531159 100644 --- a/biaweb_exporter.py +++ b/biaweb_exporter.py @@ -304,6 +304,47 @@ def generate_category_indices (dbname, conf, templates, category_str, bestrated_ # finally return true return True +# function to generate the RSS feed for the website +def generate_rss_feed (dbname, conf): + # rss main template + tpl_rss = string.Template (biaweb_strings.template_rss) + # rss item bit template + tpl_rss_itembit = string.Template (biaweb_strings.template_rss_item) + + # get the latest articles (limit by number of rss items) + arts = biaweb_db.site_latest_articles (dbname, conf[4]) + if arts == False: + return False + + rss_item_list = [] + # run through the articles and generate the rss items + for art in arts: + # link + itemlink = "http://" + conf[0] + art[13] + "/" + art[8] + ".html" + item_str = tpl_rss_itembit.safe_substitute (item_title = art[1], + item_link = itemlink, + description = art[2]) + rss_item_list.append (item_str) + + # now get the rss items as a string + rss_item_str = "".join (rss_item_list) + + # now generate the feed + rss_str = tpl_rss.safe_substitute (title = conf[1], + link = "http://" + conf[0], + description = conf[3], + rss_items = rss_item_str) + + # now try to write it to the rss file + try: + frss = open (os.path.join (conf[5], "subscribe.xml"), "w+") + frss.write (rss_str) + except IOError, OSError: + return False + + # finally return true + return True + # function to generate main index file and stylesheet def generate_home_page (dbname, conf, templates, category_str, bestrated_str): # main template @@ -408,6 +449,11 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True if ret == False: return False + # generate the rss feed + ret = generate_rss_feed (dbname, conf) + if ret == False: + return False + # generate the category directories and indices ret = generate_category_indices (dbname, conf, tpls, cats_str, best_rated_str, cats) if ret == False: diff --git a/biaweb_strings.py b/biaweb_strings.py index 8f7f232..65cb21f 100644 --- a/biaweb_strings.py +++ b/biaweb_strings.py @@ -38,7 +38,7 @@ template_main = """ + BiaWeb Qt created by V. Harishankar """ -- 2.20.1