def generate_feed(config_agent, req_path, tpl_render): folder_pages_full_path = config_agent.config.get("paths", "pages_path") cache_file_full_path = os.path.join(folder_pages_full_path, ".zw_all_pages_list_cache") buf = cache.get_all_pages_list_from_cache(config_agent) md_list = buf.split() author = config_agent.config.get("main", "maintainer_email") or "Anonymous" e_author = atom.Element(name="author") child = atom.Element(name="name", text=author) e_author.append_children(child) ts = os.stat(cache_file_full_path).st_ctime updated = atom.generate_updated(ts) ts_as_id = "timestamp:" + commons.strutils.md5(updated) feed = atom.Feed(author=e_author, id=ts_as_id, updated=updated, title="Testing Feed Output") for md_file_name in md_list[:100]: req_path = commons.strutils.rstrips(md_file_name, ".md") req_path = commons.strutils.rstrips(req_path, ".markdown") local_full_path = mdutils.req_path_to_local_full_path( req_path, folder_pages_full_path) raw_text = commons.shutils.cat(local_full_path) page_title = mdutils.get_title_by_file_path_in_md( folder_pages_full_path, req_path) static_file_prefix = static_file.get_static_file_prefix_by_local_full_path( config_agent=config_agent, local_full_path=local_full_path, req_path=req_path) view_settings = page.get_view_settings(config_agent) page_content = mdutils.md2html(config_agent=config_agent, req_path=req_path, text=raw_text, static_file_prefix=static_file_prefix, **view_settings) text = cgi.escape(commons.strutils.safestr(page_content)) e_content = atom.Element(name="content", text=text, type="html") if not page_title: continue hash_title_as_id = "md5:" + commons.strutils.md5(page_title) updated = atom.generate_updated(os.stat(local_full_path).st_ctime) entry = atom.Entry(id=hash_title_as_id, title=page_title, updated=updated, content=e_content) feed.append_children(entry) buf = str(feed) return buf
def __init__(self, iceContext, title, rep): """ IceAtomFeed Constructor @param iceContext: @type iceContext: IceContext @param title: title of the feed @type title: String @param rep: Current Repository @type rep: IceRepository @rtype: void """ self.iceContext = iceContext self.hostname = gethostbyname(gethostname()) self.iceWebPort = self.iceContext.config.port self.title = title self.rep = rep self.feed = atom.Feed()
def testConvertToAndFromString(self): feed = atom.Feed() feed.author.append(atom.Author(name=atom.Name(text='js'))) feed.title = atom.Title(text='my test source') feed.generator = atom.Generator(text='gen') feed.entry.append( atom.Entry( author=[atom.Author(name=atom.Name(text='entry author'))])) self.assert_(feed.author[0].name.text == 'js') self.assert_(feed.title.text == 'my test source') self.assert_(feed.generator.text == 'gen') self.assert_(feed.entry[0].author[0].name.text == 'entry author') new_feed = atom.FeedFromString(feed.ToString()) self.assert_(new_feed.author[0].name.text == 'js') self.assert_(new_feed.title.text == 'my test source') self.assert_(new_feed.generator.text == 'gen') self.assert_(new_feed.entry[0].author[0].name.text == 'entry author')
def test_feed(): e_link = atom.Element(name="link", href="http://example.org/2003/12/13/atom03") entry = atom.Entry(title="Atom-Powered Robots Run Amok", link=e_link, id="urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a", updated="2003-12-13T18:30:02Z", summary="Some text.") e_author = atom.Element(name="author") e_author.set_preverse_attrs("name", "John Doe") e_link = atom.Element(name="link", href="http://example.org/") feed = atom.Feed(title="Example Feed", link=e_link, updated="2003-12-13T18:30:02Z", author=e_author, id="urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6") feed.append_children(entry) buf = str(feed) # assert buf == ( # "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" # " <feed xmlns=\"http://www.w3.org/2005/Atom\">\n" # " <title>Example Feed</title>\n" # " <link href=\"http://example.org/\"/>\n" # " <updated>2003-12-13T18:30:02Z</updated>\n" # " <author>\n" # " <name>John Doe</name>\n" # " </author>\n" # " <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>\n" # " <entry>\n" # " <title>Atom-Powered Robots Run Amok</title>\n" # " <link href=\"http://example.org/2003/12/13/atom03\"/>\n" # " <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>\n" # " <updated>2003-12-13T18:30:02Z</updated>\n" # " <summary>Some text.</summary>\n" # " </entry>\n" # "</feed>\n" # ) tree = etree.fromstring(buf)
def generate_feed(posts): author = atom.Author(name=settings['author'], email=settings['email']) entries = [] for post in posts[:5]: # Rewrite post path into the weird id form I used to use. id = settings['id_base'] + '/' + ( post.timestamp.strftime('%Y-%m-%d') + '/' + os.path.splitext(os.path.basename(post.path))[0]) timestamp = post.timestamp + datetime.timedelta(seconds=time.timezone) entries.append(atom.Entry(timestamp=timestamp, id=id, title=post.title, link=settings['link'] + post.path, content=post.content)) feed = atom.Feed(title=settings['title'], id=settings['id_base'], link=settings['link'], selflink=settings['link'] + 'atom.xml', author=author, entries=entries) return feed.to_xml()