def write_output(self, rawdog, config): """Write out the current output file.""" bits = rawdog.get_main_template_bits(config) bits["items"] = self.f.getvalue() bits["num_items"] = str(len(rawdog.articles.values())) bits["dated_output_pages"] = self.generate_list() bits["dated_output_calendar"] = self.generate_calendar() bits["dated_output_calendars"] = self.generate_calendars() s = fill_template(rawdog.get_template(config), bits) fn = self.current_fn config.log("dated-output writing output file: ", fn) f = open(fn + ".new", "w") write_ascii(f, s, config) f.close() os.rename(fn + ".new", fn)
def output_write_files(rawdog, config, articles, article_dates): config.log("paged-output starting") outputfile = config["outputfile"] i = outputfile.rfind('.') if i != -1: prefix = outputfile[:i] suffix = outputfile[i:] else: prefix = outputfile suffix = "" chunks = [] while articles != []: chunks.append(articles[:articles_per_page]) articles = articles[articles_per_page:] fns = [] for i in range(len(chunks)): if i == 0: fn = prefix + suffix else: fn = "%s%d%s" % (prefix, i, suffix) fns.append(fn) for i in range(len(chunks)): fn = fns[i] date = format_time(article_dates[chunks[i][0]], config) config.log("paged-output writing ", fn, " (", date, ")") f = StringIO() dw = DayWriter(f, config) for article in chunks[i]: dw.time(article_dates[article]) rawdog.write_article(f, article, config) dw.close() bits = rawdog.get_main_template_bits(config) bits["items"] = f.getvalue() bits["num_items"] = str(len(rawdog.articles.values())) f = StringIO() f.write('<ul class="paged_output_pages">\n') for j in range(len(chunks)): latest_date = max([article_dates[a] for a in chunks[j]]) f.write('<li>') if i != j: f.write('<a href="' + os.path.basename(fns[j]) + '">') f.write(format_time(latest_date, config)) if i != j: f.write('</a>') f.write('</li>\n') f.write('</ul>\n') bits["paged_output_pages"] = f.getvalue() f = StringIO() def make_link(rel, page): if page >= 0 and page < len(chunks): f.write('<link rel="%s" href="%s">\n' % (rel, os.path.basename(fns[page]))) make_link("next", i - 1) make_link("prev", i + 1) bits["paged_output_head"] = f.getvalue() s = fill_template(rawdog.get_template(config), bits) f = open(fn + ".new", "w") write_ascii(f, s, config) f.close() os.rename(fn + ".new", fn) config.log("paged-output done") return False
def output_write(self, rawdog, config, articles): if config.no_feed_list: return True # prep map feedmap = {} feedbyname = {} for feed in config["feedslist"]: item = {} url = feed[0] name = feed[2]['define_name'] item['name'] = name.encode('utf8') for d in (config['feeddefaults'], feed[2]): for k in filter(lambda x: x.startswith('define_'), d.iterkeys()): nk = re.sub(r'^define_', '', k) item[nk] = d[k] pass pass if 'face' in item: if not '.' in item['face']: item['face'] += '.png' if not '/' in item['face']: item['face'] = '../hackergotchi/' + item['face'] item['feeds'] = [] feedmap[url] = item if not name in feedbyname: feedbyname[name] = item pass #feeds = rawdog.feeds.values() #feeds.sort(lambda a, b: cmp(a.get_blog_owner_name(config).lower(), b.get_blog_owner_name(config).lower())) for feed in rawdog.feeds.values(): itembits = {} itembits['lang'] = feed.lang for d in ('member', 'connect', 'gsoc'): if 'define_'+d in feed.args: itembits[d] = feed.args['define_'+d] itembits['url'] = cgi.escape(feed.url) title = feed.get_html_name(config) lizards_match = re.match(ur'^openSUSE\s+Lizards\s+\S+\s+(.+)$', title) if lizards_match: title = '@Lizards' itembits['title'] = title if 'link' in feed.feed_info: link = feed.feed_info['link'] lm = re.match(r'^(http://lizards\.opensuse\.org)/?$', link) if lm: link = lm.group(1) # fix lizards link m = re.match(r'^http://lizards\.opensuse\.org(/author/.+?)/feed', feed.url) if m: link += m.group(1) else: link = None pass else: #print "WARNING: no link in " + feed.url link = None if re.match(r'^https?://.+', itembits['title']): del itembits['title'] pass if link: itembits['link'] = link name = feed.args['define_name'] itembits['author'] = name if name in feedbyname: feedbyname[name]['feeds'].append(itembits) else: print "WARNING: no name match found in feedbyname for "+name pass all_names = feedbyname.keys() all_names.sort() map = [] i = 0 for name in all_names: data = feedbyname[name] if config.lang: feeds = filter(lambda x: x['lang'] == config.lang, data['feeds']) else: feeds = data['feeds'] if len(feeds) < 1: continue author = {} for k in filter(lambda x: x != 'feeds', data.keys()): author[k] = data[k] pass if i % columns == 0: author['wrap'] = True if i < columns: author['top'] = True i += 1 author['feeds'] = [] #for k in filter(lambda x: x != 'feeds', data.keys()): # feed[k] = data[k] for feed in feeds: author['feeds'].append(feed) map.append(author) feedlist_template = load_file("feedlist_template.html", config) f = codecs.open(self.out_file, "wb", encoding="utf8") feedlist_vars = {} if config.lang: feedlist_vars['lang'] = config.lang feedlist_vars['lang_'+config.lang] = True feedlist_vars['feeds'] = map f.write(fill_template(feedlist_template, feedlist_vars)) f.close() return True
def output_write_files(rawdog, config, articles, article_dates): f_hdr = StringIO() rawdoglib.plugins.call_hook("output_items_begin", rawdog, config, f_hdr) remaining = articles[:] groups = {} other_count = 0 for url, feed in rawdog.feeds.items(): if (feed.args.has_key("define_group")): group = feed.args["define_group"] group = group.replace("_", " ") if (groups.has_key(group)): groups[group]["feeds"].append(feed) else: groups[group] = {"count" : 0, "feeds" : [feed]} f = StringIO() for (key, group) in groups.items(): dw = DayWriter(f, config) f.write("<hr>\n") f.write('<h1><a name="' + key + '">' + key + '</a></h1>\n') for article in remaining[:]: for feed in group["feeds"]: if article.feed == feed.url: if not rawdoglib.plugins.call_hook("output_items_heading", rawdog, config, f, article, article_dates[article]): dw.time(article_dates[article]) rawdog.write_article(f, article, config) remaining.remove(article) group["count"] += 1 dw.close() f.write("<hr>\n") if remaining: dw = DayWriter(f, config) f.write('<h1><a name="Other">Other</a></h1>\n') for article in remaining: if not rawdoglib.plugins.call_hook("output_items_heading", rawdog, config, f, article, article_dates[article]): dw.time(article_dates[article]) rawdog.write_article(f, article, config) other_count += 1 f_hdr.write("<ul>\n") for (key, group) in groups.items(): if group["count"]: f_hdr.write('<li><a href="#%(key)s">%(key)s (%(count)d items)</a></li>\n' % {'key' : key, 'count' : group["count"]}) if other_count: f_hdr.write('<li><a href="#%(key)s">%(key)s (%(count)d items)</a></li>\n' % {'key' : 'Other', 'count' : other_count}) f_hdr.write("</ul>\n") rawdoglib.plugins.call_hook("output_items_end", rawdog, config, f) bits = rawdog.get_main_template_bits(config) bits["items"] = f_hdr.getvalue() + f.getvalue() bits["num_items"] = str(len(rawdog.articles)) rawdoglib.plugins.call_hook("output_bits", rawdog, config, bits) s = fill_template(rawdog.get_template(config), bits) outputfile = config["outputfile"] if outputfile == "-": write_ascii(sys.stdout, s, config) else: config.log("Writing output file: ", outputfile) f = open(outputfile + ".new", "w") write_ascii(f, s, config) f.close() os.rename(outputfile + ".new", outputfile) return False