[gimp-web/mirrors-test] Added html generator to mirrors plugin



commit 0e49f855f78ee54287a4f744576bdab49076833f
Author: Pat David <patdavid gmail com>
Date:   Tue Dec 29 16:43:02 2015 -0600

    Added html generator to mirrors plugin

 plugins/gimp_mirrors/gimp_mirrors.py |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/plugins/gimp_mirrors/gimp_mirrors.py b/plugins/gimp_mirrors/gimp_mirrors.py
index 5853e7c..8ef0d36 100644
--- a/plugins/gimp_mirrors/gimp_mirrors.py
+++ b/plugins/gimp_mirrors/gimp_mirrors.py
@@ -20,6 +20,26 @@ I am not kidding.
 
 class UnexpectedException(Exception): pass
 
+def html_output( data ):
+
+    html = u"<dl class='download-mirror'>\n"
+
+    for key, values in sorted(data.iteritems()):
+
+        html += u"<dt>{}</dt>".format( key )
+
+        for value in values:
+            if isinstance( value, unicode ):
+                tmp = value
+            else:
+                tmp = unicode( value, 'utf_8')
+            html += u"<dd><a href='{}'>{}</a></dd>\n".format( tmp, tmp )
+
+    html += u"</dl>"
+
+    return html
+
+
 def do_mirrors(content_object):
     # Not 'Page' object?  Quit.
     if type(content_object) is not contents.Page:
@@ -47,12 +67,12 @@ def do_mirrors(content_object):
             data = json.load(data_file)
 
         for record in data:
-            print "####"
-            print record
+            #print "####"
+            #print record
 
             try:
                 country = gi.country_name_by_name( record )
-                print country
+                #print country
 
                 if country in mirrors:
                     mirrors[ country ] += data[ record ]
@@ -62,11 +82,11 @@ def do_mirrors(content_object):
             except:
                 print "cannot resolve record: ", record
 
-        print( mirrors )
-
-        page._content = page.content.replace(u"<!-- MIRRORS -->", u"<h2>Mirrors Test</h2>")
-
+        #html_output( mirrors )
+        #print( html_output( mirrors ) )
 
+        #page._content = page.content.replace(u"<!-- MIRRORS -->", u"<h2>Mirrors Test</h2>")
+        page._content = page.content.replace(u"<!-- MIRRORS -->", html_output( mirrors) )
 
     
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]