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

cgrzemba at users.sourceforge.net cgrzemba at users.sourceforge.net
Fri Jan 25 13:26:44 CET 2019


Revision: 26505
          http://sourceforge.net/p/gar/code/26505
Author:   cgrzemba
Date:     2019-01-25 12:26:38 +0000 (Fri, 25 Jan 2019)
Log Message:
-----------
add css styling and some extensions

Modified Paths:
--------------
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json

Added Paths:
-----------
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/answer.html.tmpl
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/export-osqa-db.py
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_answer_html.py
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_quest_html.py
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/question.html.tmpl

Removed Paths:
-------------
    csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py

Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/answer.html.tmpl
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/answer.html.tmpl	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/answer.html.tmpl	2019-01-25 12:26:38 UTC (rev 26505)
@@ -0,0 +1,58 @@
+<link href="../../css/style.css" rel="stylesheet" type="text/css" media="all">
+<html>
+<head>
+  <div id="logo">
+  </div>
+</head>
+<body>
+<div id="banner">
+<ul id="answ">
+<li id="answ">
+<a href="http://www.opencsw.org" title="OpenCSW Solaris packages">Home</a>
+</li>
+<li id="answ">
+<a href="http://www.opencsw.org/community" title="OpenCSW OSQA">Questions</a>
+</li>
+</ul>
+</div>
+<h1>
+{{ title }}
+</h1>
+<p>
+{{ body }}
+</p>
+<p>
+asked: {{ added_at|datetimeformat }}
+by: {{ username }}
+
+</p>
+{% for com in comment %}
+<hr />
+<p>
+{{ com.username }} commented:
+</p>
+<p>
+{{ com.body }}
+</p>
+{% endfor %}
+
+{% for ans in answer %}
+<hr />
+<p>
+{{ ans.username }} answers:
+</p>
+<p>
+{{ ans.body }}
+</p>
+{% for com in ans.comment %}
+<hr />
+<p>
+{{ com.username }} commented:
+</p>
+<p>
+{{ com.body }}
+</p>
+{% endfor %}
+{% endfor %}
+</body>
+</html>

Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/export-osqa-db.py
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/export-osqa-db.py	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/export-osqa-db.py	2019-01-25 12:26:38 UTC (rev 26505)
@@ -0,0 +1,60 @@
+import MySQLdb
+import json
+from datetime import date, datetime
+
+SPAMMERS = ['raggieapauly']
+
+def json_serial(obj):
+    """JSON serializer for objects not serializable by default json code"""
+
+    if isinstance(obj, (datetime, date)):
+        return obj.isoformat()
+    raise TypeError ("Type %s not serializable" % type(obj))
+ 
+db = MySQLdb.connect(host="dbchbie01",  # your host 
+                     user="osqacsw2_prod",       # username
+                     passwd="NoisHevryb",     # password
+                     db="osqacsw2_prod")   # name of the database
+ 
+# Create a Cursor object to execute queries.
+cur = db.cursor()
+cur = db.cursor (MySQLdb.cursors.DictCursor)
+ 
+# Select data from table using SQL query.
+cur.execute("select n.id, n.parent_id, n.abs_parent_id, a.username, u.real_name, n.node_type, n.title, n.body, n.added_at from forum_node n,forum_user u, auth_user a where n.author_id = u.user_ptr_id and n.author_id = a.id and a.is_active = 1;")
+ 
+# print the first and second columns      
+
+questions = [];
+answers = [];
+comments = [];
+for row in cur.fetchall() :
+    if row['username'] not in SPAMMERS:
+        if row['node_type'] == 'question':
+            row['answer'] = []
+            row['comment'] = []
+            questions.append(row)
+        elif row['node_type'] == 'answer':
+            answers.append(row)
+        elif row['node_type'] == 'comment':
+            comments.append(row)
+for answer in answers:
+    try:
+        for q in questions:
+            if q['id'] == answer['abs_parent_id']:
+                answer['comment'] = []	
+                q['answer'].append(answer)
+    except IndexError as e:
+        import pdb; pdb.set_trace();
+for comment in comments:
+    try:
+        for a in answers:
+            if a['id'] == comment['parent_id']:
+                a['comment'].append(comment)
+    except IndexError as e:
+        import pdb; pdb.set_trace();
+
+import pdb; pdb.set_trace()
+
+with open('/var/tmp/threads.json', 'w') as outfile:
+    json.dump(questions, outfile, default = json_serial)

Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_answer_html.py
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_answer_html.py	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_answer_html.py	2019-01-25 12:26:38 UTC (rev 26505)
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+import re
+import os
+import os.path
+import json
+import pprint
+import datetime
+from jinja2 import Template, environmentfilter, Environment, FileSystemLoader
+
+HTML_PATH="/home/cgrzemba/public_html/osqa-static"
+ENCODING = 'utf-8'
+SPAMMERS = ['maloriegrebetr']
+
+ at environmentfilter
+def datetimeformat(env, date, fmt='%Y-%m-%d'):
+    date = datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S")
+    native = date.replace(tzinfo=None)
+    return native.strftime(fmt) 
+
+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:
+        if e.errno != 17: # path already exists
+            import pdb; pdb.set_trace()
+
+    with open(os.path.join(root_dir, filename), 'w') as fd:
+        fd.write(content.encode(ENCODING))
+
+def ProcessQuestion(question):
+    id = question['id']
+    slug = Slugify(question['title'])
+    dir_name_2 = str(id) + '/' + slug
+    filename = dir_name_2 + '/index.html'
+
+    env = Environment(loader=FileSystemLoader(searchpath="./"))
+    env.filters['datetimeformat'] = datetimeformat
+    tmpl = env.get_template('answer.html.tmpl')
+    html = tmpl.render(**question)
+    WriteFile(HTML_PATH, dir_name_2, filename, html)
+
+
+def main():
+    with open('threads.json') as fd:
+        questions = json.load(fd)
+    for question in questions:
+        if question['username'] not in SPAMMERS:
+            ProcessQuestion(question)
+
+if __name__ == '__main__':
+    main()


Property changes on: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_answer_html.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Deleted: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py	2019-01-24 14:43:42 UTC (rev 26504)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_html.py	2019-01-25 12:26:38 UTC (rev 26505)
@@ -1,62 +0,0 @@
-#!/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/generate_quest_html.py
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_quest_html.py	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_quest_html.py	2019-01-25 12:26:38 UTC (rev 26505)
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import re
+import os
+import os.path
+import json
+import pprint
+import datetime
+from jinja2 import Template, environmentfilter, Environment, FileSystemLoader
+
+HTML_PATH="/home/cgrzemba/public_html/osqa-static"
+filename = 'index.html'
+ENCODING = 'utf-8'
+SPAMMERS = ['maloriegrebetr']
+
+ at environmentfilter
+def slugify(env, s):
+    return '-'.join(x for x in re.findall('[0-9a-z_]*', s.lower()) if x)
+
+def ProcessQuestion(questions):
+    env = Environment(loader=FileSystemLoader(searchpath="./"))
+    env.filters['slugify'] = slugify
+    tmpl = env.get_template('question.html.tmpl')
+    qd = {'questions': questions }
+    import pdb; pdb.set_trace()
+    html = tmpl.render(**qd)
+    with open(os.path.join(HTML_PATH, filename), 'w') as fd:
+        fd.write(html.encode(ENCODING))
+
+def main():
+    with open('threads.json') as fd:
+        questions = json.load(fd)
+        ProcessQuestion(questions)
+
+if __name__ == '__main__':
+    main()


Property changes on: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/generate_quest_html.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/question.html.tmpl
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/question.html.tmpl	                        (rev 0)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/question.html.tmpl	2019-01-25 12:26:38 UTC (rev 26505)
@@ -0,0 +1,30 @@
+<link href="./css/style.css" rel="stylesheet" type="text/css" media="all">
+<html>
+<head>
+  <div id="logo">
+  </div>
+</head>
+<body>
+<div id="banner">
+<ul id="answ">
+<li id="answ">
+<a href="http://www.opencsw.org" title="OpenCSW Solaris packages">Home</a>
+</li>
+<li id="answ">
+<a href="http://www.opencsw.org/community" title="OpenCSW OSQA">Questions</a>
+</li>
+</ul>
+</div>
+<h1>
+OSQA Community questions
+</h1>
+</p>
+<ul id="quest">
+{% for quest in questions %}
+<li>
+<a href={{ quest.id }}/{{ quest.title|slugify }}/index.html >{{ quest.title }}</a>
+</li>
+{% endfor %}
+</ul>
+</body>
+</html>

Modified: csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json
===================================================================
--- csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json	2019-01-24 14:43:42 UTC (rev 26504)
+++ csw/mgar/pkg/opencsw-manual/trunk/files/osqa-migration/threads.json	2019-01-25 12:26:38 UTC (rev 26505)
@@ -1 +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