X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=biaweb_exporter.py;h=b940867d551525115f7786c31e66492852a30867;hp=47ccead604a630035add1810e3ccb90a986b987e;hb=1e98086e7040991b7aa6904fbac30f256a84f299;hpb=df54af4f6bf7afa6b89f5fa1f07177313aa5cc1f diff --git a/biaweb_exporter.py b/biaweb_exporter.py index 47ccead..b940867 100644 --- a/biaweb_exporter.py +++ b/biaweb_exporter.py @@ -76,7 +76,7 @@ def generate_search_index (dbname, conf, full_text_index = True): # get all the articles arts = biaweb_db.site_articles (dbname) # if cannot get articles - if arts == False: + if arts is False: return False # if full text index, then field should be article content otherwise keywords @@ -202,7 +202,7 @@ def generate_article_pages (dbname, conf, templates, category_str, bestrated_str # get all articles from the database articles = biaweb_db.site_articles (dbname) - if articles == False: + if articles is False: return # walk through each article and generate the file in the appropriate category @@ -258,7 +258,7 @@ def generate_category_indices (dbname, conf, templates, category_str, bestrated_ # now get the list of articles for the specified category articles_list = biaweb_db.site_articles (dbname, cat[0]) - if articles_list == False: + if articles_list is False: return False tableitems = [] @@ -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 is 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 @@ -315,7 +356,7 @@ def generate_home_page (dbname, conf, templates, category_str, bestrated_str): # get the latest articles - conf[4] is num of rss entries to be used also latest_arts = biaweb_db.site_latest_articles (dbname, conf[4]) - if latest_arts == False: + if latest_arts is False: return False news_items = [] @@ -375,13 +416,19 @@ def generate_home_page (dbname, conf, templates, category_str, bestrated_str): def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True): # get the configuration conf = biaweb_db.get_configuration (dbname) + # if cannot get configuration + if conf is False: + return False + # get the templates tpls = biaweb_db.get_templates (dbname) + if tpls is False: + return False # get the list of categories cats = biaweb_db.get_categories (dbname) # cannot get categories return false - if cats == False: + if cats is False: return False # format the categories as a html bulleted list @@ -390,7 +437,7 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True # get the best rated articles best_rated = biaweb_db.site_get_bestrated (dbname) # if cannot retrieve - if best_rated == False: + if best_rated is False: return False # format the best rated articles as a html bulleted list best_rated_str = html_format_best_rated (best_rated) @@ -405,27 +452,32 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True # generate the index page including style sheet ret = generate_home_page (dbname, conf, tpls, cats_str, best_rated_str) - if ret == False: + if ret is False: + return False + + # generate the rss feed + ret = generate_rss_feed (dbname, conf) + if ret is 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: + if ret is False: return False # generate the article pages ret = generate_article_pages (dbname, conf, tpls, cats_str, best_rated_str) - if ret == False: + if ret is False: return False # copy other files/folders into the destination path ret = copy_files_folders (conf, files_to_copy, folders_to_copy) - if ret == False: + if ret is False: return False # now generate the search index database ret = generate_search_index (dbname, conf, search_type_full) - if ret == False: + if ret is False: return False # finally when all is successfully done return true