SF.net SVN: gar:[26501] csw/mgar/pkg/opencsw-manual/trunk/files

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Jan 20 22:15:37 CET 2019


Revision: 26501
          http://sourceforge.net/p/gar/code/26501
Author:   wahwah
Date:     2019-01-20 21:15:33 +0000 (Sun, 20 Jan 2019)
Log Message:
-----------
opencsw-manual: A tool to migrate from OSQA to HTML.

Added Paths:
-----------
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/README.md
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json

Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/README.md
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/README.md	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/README.md	2019-01-20 21:15:33 UTC (rev 26501)
@@ -0,0 +1,5 @@
+osqa-migration
+==============
+
+A tool to generate HTML from a JSON file as exported from the OSQA MySQL
+database.

Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py	2019-01-20 21:15:33 UTC (rev 26501)
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+import re
+import os
+import os.path
+import json
+import pprint
+from jinja2 import Template
+
+QUESTION_TMPL = """
+<html>
+<head>
+{{ title }}
+</head>
+<body>
+{{ body }}
+<p>
+by: {{ username }}
+</p>
+{% for ans in answer %}
+<hr />
+<p>
+{{ ans.username }} answers:
+</p>
+<p>
+{{ ans.body }}
+</p>
+{% endfor %}
+</body>
+</html>
+"""
+
+def Slugify(s):
+    return '-'.join(x for x in re.findall('[0-9a-z_]*', s.lower()) if x)
+
+def WriteFile(root_dir, dir2, filename, content):
+    try:
+        os.makedirs(os.path.join(root_dir, dir2))
+    except OSError as e:
+        pass
+    with open(os.path.join(root_dir, filename), 'w') as fd:
+        fd.write(content)
+
+def ProcessQuestion(question):
+    id = question['id']
+    slug = Slugify(question['title'])
+    dir_name_2 = str(id) + '/' + slug
+    filename = dir_name_2 + '/index.html'
+
+    tmpl = Template(QUESTION_TMPL)
+    html = tmpl.render(**question)
+    WriteFile('/home/maciej/public_html/osqa-static', dir_name_2, filename, html)
+
+
+def main():
+    with open('threads.json') as fd:
+        questions = json.load(fd)
+    for question in questions:
+        ProcessQuestion(question)
+
+if __name__ == '__main__':
+    main()

Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json	2019-01-20 21:15:33 UTC (rev 26501)
@@ -0,0 +1 @@

@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list