commit 25afb191764c169c17343c1028a5366b9c5900f0 Author: hiro hiro@torproject.org Date: Mon Sep 2 19:07:47 2019 +0200
Refactor plugin --- packages/xml-to-html/lektor_xml_to_html.py | 36 +++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/packages/xml-to-html/lektor_xml_to_html.py b/packages/xml-to-html/lektor_xml_to_html.py index b25eb82..ead0817 100644 --- a/packages/xml-to-html/lektor_xml_to_html.py +++ b/packages/xml-to-html/lektor_xml_to_html.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- #pylint: disable=wrong-import-position import sys -import os
PY3 = sys.version_info > (3,)
@@ -10,15 +9,26 @@ from lektor.pluginsystem import Plugin from xml.etree import ElementTree as etree from urllib import request
-webFile = request.urlopen("https://blog.torproject.org/events.xml") -content = webFile.read() -root = etree.fromstring(content) -items = root.findall('channel/item') -os.chdir(os.path.dirname(__file__)) -print(os.getcwd()) -file_object = open('../../../templates/stream.html', 'w') -for entry in items: - title = entry.findtext('title') - link = entry.findtext('link') - file_object.write("<h3><a href="" + link +"">" + title + "</a></h3>") - file.close() + +class DisqusCommentsPlugin(Plugin): + name = u'XML to HTML' + description = u'Lektor plugin to add an XML feed as HTML.' + + + def on_setup_env(self, **extra): + + def stream(identifier=None, url=None): + webFile = request.urlopen("https://blog.torproject.org/events.xml") + content = webFile.read() + root = etree.fromstring(content) + items = root.findall('channel/item') + file_object = open('../../../templates/stream.html', 'w') + stream = "" + for entry in items: + title = entry.findtext('title') + link = entry.findtext('link') + stream += "<h3><a href="" + link +"">" + title + "</a></h3>") + + return stream + + self.env.jinja_env.globals['render_strean'] = stream
tor-commits@lists.torproject.org