From 4fbfd6b88a7d9e2b825d5a01b63843eacc68f590 Mon Sep 17 00:00:00 2001
From: Castro0o <andre@andrecastro.info>
Date: Tue, 28 Apr 2015 09:31:10 +0200
Subject: [PATCH] rewriting all mechanism from scrath - w/out json

---
 allworks_mmdc.json     |  1 -
 mmdc_modules.py        | 56 ++++++++++++++++++++++++++++++++++++++++--
 mmdc_pages.py          | 25 +++++++++++--------
 prototype_page.py      | 31 +++++++++++++++++++++++
 web/page-template.html | 22 +++++++++++++++++
 5 files changed, 122 insertions(+), 13 deletions(-)
 delete mode 100644 allworks_mmdc.json
 create mode 100755 prototype_page.py
 create mode 100644 web/page-template.html

diff --git a/allworks_mmdc.json b/allworks_mmdc.json
deleted file mode 100644
index decbf81..0000000
--- a/allworks_mmdc.json
+++ /dev/null
@@ -1 +0,0 @@
-{"16005": {"Website": "www.artyomkocharyan.com", "Bio": "Artyom Kocharyan (AM) is visual artist based in Rotterdam. His work explores the contemporary visual culture, namely the culture of images that increasingly dominate the world of communication. Artyom\u2019s work is concerned with the representation aspect of images and their ability to determine our vision of the world. Artyom is engaged with the representation apparatus that is peculiar to current digital and online culture.", "Description": "Artyom\u2019s work entitled \u201cNew Image\u201d is a series of images of that have been made using Google Image search results. In his work Artyom explores the relations between images and the technology that is responsible for their production and distribution. Namely how technological endeavors came to affect the dynamics within image culture. ", "Creator": "Artyom", "Title": "Artyom-graduation-work", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/thumb/6/6a/Screen_Shot_2014-10-26_at_16.10.08.jpg/500px-Screen_Shot_2014-10-26_at_16.10.08.jpg", "Date": "2015", "Thumbnail": "Screen Shot 2014-10-26 at 16.10.08.jpg"}, "15974": {"Date": "2015", "Creator": "JOK", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/thumb/a/af/22xxxxx.jpg/500px-22xxxxx.jpg", "Thumbnail": "22xxxxx.jpg", "Title": "Ahhhh"}, "16007": {"Bio": "Henk-Jelle de Groot is a Rotterdam based sound designer and musician. After graduating with an Audio / Visual design bachelor Henk-Jelle setup a sound studio in Rotterdam to work in the Audio / Visual industry. After 7 years of working he returned to the Piet Zwart Institute to graduate in a Master of comm design something something. In addition to working in the Audio / Visual industry, he is muscian and builder of electronic instruments.", "Description": "Untitled is a work about visualizing non audible and non visual acoustic properties of a space. Every space has a certain acoustic reverberation, a property that can't be heard or seen on it's own. With this project I aim to visualize that property trough data visualization. Untitled contains a (few) examples of spaces that have been mapped and visualized in a new form and material. These sculptures are presented in a way that the viewer may contextualize on it's own what the nature of the sculpture is", "Creator": "Henk-Jelle de Groot", "Title": "U_ntitled", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/e/e7/9m4MBqRM1w-6.png", "Date": "2015", "Thumbnail": "9m4MBqRM1w-6.png"}, "15982": {"Bio": "Ana Lu\u00edsa Moura (PT) has a background in Architecture / Urban Planning and is currently exploring means of visual storytelling and strategic illustration. Her research focuses on photographical protocols within media imagery, regarding in particular the instrumentalization of vulnerability and personal exposure.", "Creator": "Ana Lu\u00edsa Moura", "Title": "The_Aesthetics_of_Ethics", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/b/bd/Collage_007_thumbnail.jpg", "Date": "2015", "Thumbnail": "collage_007_thumbnail.jpg", "Extra": "The Aesthetics of Ethics is a reflection on the way social documentary photography shapes ethical concern. The aesthetics of these photographs map out a set of emotional reactions to social issues, tailoring a form of political consciousness. The project associated with the theoretical research, an illustration exercise, unfolds and explores the visual grammar of the genre. Attention to details of a manufactured informality allows the understanding of the images as an encoded language, detaching it from the objectivity and authority of the photographical medium (...)"}, "15986": {"Website": "http://joak.nospace.at", "Bio": "My Bio", "Description": "my description", "Creator": "Joseph Knierzinger", "Title": "User:Joak/graduation/catalog1", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/1/16/Pointer.gif", "Date": "2015", "Thumbnail": "pointer.gif", "Extra": "my free text"}, "16025": {"Website": "www.example.com", "Bio": "The\n =bio= is coming soon.", "Description": "Mina is a smart chat bot, a commercial project designed by a promising startup to fulfill humans' need of talking to someone else in a world where communication has become almost completely mediated by social media services. To keep the illusion alive, the software aims to be invisible.", "Creator": "Lucia Dossin", "Title": "Mina", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/5/59/3legs.jpg", "Date": "2015", "Thumbnail": "3legs.jpg", "Extra": "TEST\n===\"free text - short version\" 203 words==="}, "15965": {"Website": "https://en.wikipedia.org/wiki/Luther_Blissett_%28nom_de_plume%29", "Bio": "Luther Blissett is a multiple-use name.", "Creator": "Luther Blisset", "Title": "Qq", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/thumb/8/85/Luther-blissett-300.jpg/500px-Luther-blissett-300.jpg", "Date": "2015", "Thumbnail": "Luther-blissett-300.jpg", "Extra": "While the \"folk heroes of\" the early-modern period and the nineteenth century served a variety of social and political purposes, the Luther Blissett Project (LBP) were able to utilize the media and communication strategies unavailable to their predecessors. According to Marco Deseriis, the main purpose of the LBP was to create \"a folk hero of the information society\""}, "15999": {"Website": "http://maxdovey.com", "Bio": "My Bio", "Description": "How to be more or less human.", "Creator": "Max Dovey", "Title": "User:Max_Dovey/maxgradbio", "Thumbnail_url": "http://pzwiki.wdka.nl/mw-mediadesign/images/1/16/Pointer.gif", "Date": "2015", "Thumbnail": "pointer.gif", "Extra": "A solo performance exploring identity, perception and representation through automatic image analysis software. Software that is used to automatically  tag online images is used to direct a live performance. Each scene is performed alongside software that reacts and interprets the performers actions. The performance explores the potential threat of computer vision and automated image perception on the human body. Every movement of the performance is analysed in detail to reductive categorisation."}}
diff --git a/mmdc_modules.py b/mmdc_modules.py
index 28f4ebd..83c88c3 100644
--- a/mmdc_modules.py
+++ b/mmdc_modules.py
@@ -64,11 +64,59 @@ def write_html_file(html_tree, filename):
     edited.write(html)
     edited.close()
 
+# mw article modules
 
+def parse_work_page(title, content):
+#    content = content.encode('utf-8')
+    if re.match('\{\{\Graduation work', content):
+        work_dict = {}
+        work_dict['Title']=title
+        template, extra = (re.findall('\{\{Graduation work\n(.*?)\}\}(.*)', content, re.DOTALL))[0]
+        # template's key/value pair
+        keyval = re.findall('\|(.*?)\=(.*?\n)', template, re.DOTALL)
+        if extra:
+            extra = ('Extra', extra)
+            keyval.append(extra)
+
+#        checkkeys = [keyval[i] for i in range(len(keyval)) if keyval[i][0] in mainkeys and len(keyval[i][1])>3] #list mainkeys present, w/ values, in tuples [(key, val),(key, val)...]
+ #       if len(checkkeys) == 3 : # checkkeys contains all mainkeys and values 
+            for pair in keyval:
+                key = pair[0]
+                val = pair[1]
+                val = val.replace('\n','')            
+                if 'Creator' in key:
+                    val = val.replace(', ', '')
+                elif 'Thumbnail' in key:
+                    thumburl = api_thumb_url(val)
+                    work_dict['Thumbnail_url']=thumburl
+                    print 'THUMB:', thumburl
+                work_dict[key]=val
+            return work_dict, extra
+
+
+# Alternative to parse_work_page - W/out dictionary        
+def parse_work(title, content):
+    if re.match('\{\{\Graduation work', content):
+        template, extra = (re.findall('\{\{Graduation work\n(.*?)\}\}(.*)', content, re.DOTALL))[0]
+        # template's key/value pair
+        keyval = re.findall('\|(.*?)\=(.*?\n)', template, re.DOTALL)
+        for pair in keyval:
+            key = pair[0]
+            val = pair[1]
+            if 'Description' in key:
+                description = val
+
+        print keyval
+        
+    return extra, description
+
+
+
+    
 # Conversion Modules
 def pandoc2html(mw_content):
     if mw_content:
-        mw_content = mw_content.encode('utf-8')
+        mw_content = mw_content#.encode('utf-8')
         # convert from mw to html
         args_echo =shlex.split( ('echo "{}"'.format(mw_content)) )
         args_pandoc = shlex.split( 'pandoc -f mediawiki -t html5' )
@@ -90,7 +138,11 @@ def pandoc(filename, title, creator, date, website, thumbnail, bio, description,
 #    return html
 
 # pandoc either reades input from stdin or through input file
-# pandoc DOES NOT convert variables
+# pandoc DOES NOT convert variables; it has to receive the input from stdin.
+# to create html convert: bio, description, extra, of at time
+# insert them into HTML template by:
+## gerating html in python? and insertion sub elements ?
+## ??
                                
                                #     pandoc = 'pandoc -s -f mediawiki -t html5 \
 # --template template_article.html \
diff --git a/mmdc_pages.py b/mmdc_pages.py
index cf5a0c8..2ed7ec7 100755
--- a/mmdc_pages.py
+++ b/mmdc_pages.py
@@ -183,16 +183,21 @@ for key in json_allworks.keys():
 
     print work_file, website
     # if key in work.keys() else ''
-    pandoc( filename=work_file, \
-            template='web/work-template.html', \
-            title=title, \
-            creator=creator, \
-            date=date, \
-            website=website, \
-            thumbnail=thumbnail, \
-            bio=bio, \
-            description=description, \
-            extra=extra ) # convert to HTML
+
+    if extra:
+        extra_html = pandoc2html(extra)
+        print (extra_html)
+
+    # pandoc( filename=work_file, \
+    #         template='web/work-template.html', \
+    #         title=title, \
+    #         creator=creator, \
+    #         date=date, \
+    #         website=website, \
+    #         thumbnail=thumbnail, \
+    #         bio=bio, \
+    #         description=description, \
+    #         extra=extra ) # convert to HTML
     # print '= = = = = = ='
     # print html_content 
     # print '= = = = = = ='
diff --git a/prototype_page.py b/prototype_page.py
new file mode 100755
index 0000000..6f493e0
--- /dev/null
+++ b/prototype_page.py
@@ -0,0 +1,31 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+###########
+# Testing downloading and converting mw page content to html
+###########
+from mmdc_modules import api_request, api_page, api_thumb_url, pandoc2html, parse_work_page, parse_work
+
+template = open("web/page-template.html", "r")
+template =  template.read()
+template =  template.format(title="This is My Title", creator='', date='', website='', thumbnail='', bio='',description='', extra=''  )
+# download
+pageid='15965'
+article = api_page(pageid, 'content')
+#print article
+#print '----------- article -----'
+
+# parsing article
+extra, description = parse_work('Qq', article)
+
+# placing mw content inside dict makes it non convertable. Why?
+#print extra #work_dict['Extra']
+
+html_extra = pandoc2html(extra.encode('utf-8'))
+html_description = pandoc2html(description.encode('utf-8'))
+
+print '----------- html -----'
+print html_description
+#print html_extra
+
+print template
diff --git a/web/page-template.html b/web/page-template.html
new file mode 100644
index 0000000..c240ceb
--- /dev/null
+++ b/web/page-template.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="UTF-8">
+    <title>{title}</title> <!-- Work title will go to here --> 
+    <link rel="stylesheet" href="css/style.css">
+  </head>
+  <body>
+    <div id="header">
+      <div id="title"><h1>{title}</h1></div>
+      <div id="creator"><h2>{creator}</h2></div>
+      <div id="date">{date}</div>
+      <div id="website"><a href="{website}">{website}</a></div>
+      <div id="thumbnail"><img src="{thumbnail}" class="" alt="" /></div>
+      <div id="bio">{bio}</div>
+    </div>    
+    <div id="body">
+      <div id="description">{description}</div>
+      <div id="extra">{extra}</div>
+    </div>
+  </body>
+</html>