diff --git a/mmdc_modules.py b/mmdc_modules.py
index 79c47e5..4e61b44 100644
--- a/mmdc_modules.py
+++ b/mmdc_modules.py
@@ -79,8 +79,10 @@ def api_thumb_url(filename):
# PROCESSING MODULES
def write_html_file(html_tree, filename):
+ print 'WRITE HTML FILE'
doctype = ""
- html = doctype + ET.tostring(html_tree, encoding='utf-8', method='html')
+ print 'TREE', type(html_tree)
+ html = doctype + ET.tostring(html_tree, method='html', encoding='utf-8', )
edited = open(filename, 'w') #write
edited.write(html)
edited.close()
@@ -121,7 +123,7 @@ def pandoc2html(mw_content):
gallery_exp=re.compile('(.*?) ', re.S)
-imgfile_exp=re.compile('(File:(.*?)\.(gif|jpg|jpeg|png|svg))')
+imgfile_exp=re.compile('(File:(.*?)\.(gif|jpg|jpeg|png))')
def replace_gallery(content):
content = re.sub(imgfile_exp, '[[\g<1>]]', content) #add [[ ]] to File:.*?
@@ -146,6 +148,10 @@ def index_addwork(parent, workid, href, thumbnail, title, creator, date):
'data-creator':creator,
'data-date':date})
- grandchild_a = ET.SubElement(child_div, 'a', attrib={'href':href, 'class':'work'})
- grandgrandchild_img = ET.SubElement(grandchild_a, 'img', attrib={'class':'work', 'src':thumbnail})
+ grandchild_a = ET.SubElement(child_div, 'a', attrib={'href':href, 'class':'work'})
+ if thumbnail is '':
+ grandgrandchild_h3 = ET.SubElement(grandchild_a, 'h3', attrib={'class':'work', 'id':'thumbnail_replacement'})
+ grandgrandchild_h3.text=title
+ else:
+ grandgrandchild_img = ET.SubElement(grandchild_a, 'img', attrib={'class':'work', 'src':thumbnail})
# need to add css width to div.item
diff --git a/mmdc_wiki2web.py b/mmdc_wiki2web.py
index 46f2b8c..9b83229 100755
--- a/mmdc_wiki2web.py
+++ b/mmdc_wiki2web.py
@@ -37,15 +37,9 @@ endpoint = "http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&"
# CREATE INDEX
########
memberpages=mw_cats(args)
+#memberpages['Ctrl-F Reader','As We Speak']
print 'memberpages', memberpages
-#memberpages = api_pagesincategories('Graduation work', '2015') #list, containing dictionary of all pages ids. Example: [{u'ns': 0, u'pageid': 15974, u'title': u'Ahhhh'}, {u'ns': 0, u'pageid': 16005, u'title': u'Artyom-graduation-work'}]
-#memberpages = [{u'ns': 0, u'pageid': 15982, u'title': u'The Aesthetics of Ethics'}]
-#memberpages = [{u'ns': 0, u'pageid': 16005, u'title': u'Artyom-graduation-work'}]
-#memberpages = [{u'ns': 0, u'pageid': 16007, u'title': u'U ntitled'}]
-#memberpages = [{u'ns': 0, u'pageid': 15965, u'title': u'Qq'}]
-## output: memberpages [{u'ns': 0, u'pageid': 15982, u'title': u'The Aesthetics of Ethics'}]
-
########
# Templates
@@ -72,27 +66,35 @@ for member in memberpages:
workpage_mw = replace_gallery(workpage_mw)
workpage_mw = replace_video(workpage_mw)
workdict = parse_work(member, workpage_mw) # create dictionary workpage_mw template
+ if len(workdict['Creator'])>1 and len(workdict['Title'])>1 and len(workdict['Description'])>1:
+ for key in workdict.keys(): # convert Extra, Description, Bio to HTML
+ if key in ['Extra', 'Description', 'Bio'] and workdict[key]:
+ workdict[key] = pandoc2html( (workdict[key].decode('utf-8')))
+ elif key in ['Creator']:
+ workdict[key] = workdict[key].replace(',','' ) #remove comma
+
+ #replace empty dict values with ' ' # to avoid empty tags
+ for key in workdict.keys():
+ if workdict[key] is '' and key is not 'Thumbnail':
+ workdict[key] = ' '
+ elif key is 'Thumbnail' and workdict[key]:
+ img = ' '.format(workdict[key])
+ # append img to text
+ workdict[key] = workdict[key] # + img
+ print 'THUMB', workdict[key]
- for key in workdict.keys(): # convert Extra, Description, Bio to HTML
- if key in ['Extra', 'Description', 'Bio'] and workdict[key]:
- workdict[key] = pandoc2html( (workdict[key].decode('utf-8')) )
-
-
-
- print 'EXTRA', type (workdict['Extra']), workdict['Extra']
- # fill template with dictionary/mw_page values
- pprint.pprint(workdict)
-
- if len(workdict['Creator'])>1 and len(workdict['Creator'])>1:
+ if type(workdict[key]) is unicode:
+ workdict[key]=workdict[key].encode('utf-8')
+ # print workdict[key]
- workpage_html = page_template.format(title=('Title'),#workdict['Title']),
- creator=(workdict['Creator']),
+ workpage_html = page_template.format(title=workdict['Title'],
+ creator=workdict['Creator'],
date=workdict['Date'],
website=workdict['Website'],
thumbnail=workdict['Thumbnail'],
- bio=(workdict['Bio']),
- description=(workdict['Description']),
- extra=( workdict['Extra'] )
+ bio=workdict['Bio'],
+ description=workdict['Description'],
+ extra=workdict['Extra']
)
# parse workpage_html # process html: img full url
@@ -105,33 +107,31 @@ for member in memberpages:
if newsrc:
img.set('src', newsrc)
- website = tree.find('.//p[@class="hightlightSidebar"]/a')
- if not website.get('href'): # if no website link.
- #remove empty .//p[@class="hightlightSidebar"]/a
- website_parent = tree.find('.//p[@class="hightlightSidebar"]')
- website_parent.remove(website)
-
+ #######
+ # INDEX
+ #######
# save workpage_html
workpage_html = ET.tostring(tree)
- creator = workdict['Creator'].decode('ascii', 'ignore')
+ creator = workdict['Creator']#.decode('ascii', 'ignore')
creator = creator.replace(' ','_')
work_filename = 'web/{}-{}.html'.format(workdict['Date'], creator)
work_file = open(work_filename, "w")
work_file.write(workpage_html)
work_file.close()
-
-
- print 'DICT', type(workdict['Title'])
- # insert work to index
+
+ # insert work to index
index_addwork( parent=index_container,
workid=key,
href=work_filename.replace('web/',''),
- title=(workdict['Title']),#.decode('utf-8'),
- creator=workdict['Creator'].decode('utf-8'),
+ title=workdict['Title'],#.decode('utf-8'),
+ creator=workdict['Creator'],#.decode('utf-8'),
date=workdict['Date'],
- thumbnail=workdict['Thumbnail'],
+ thumbnail=workdict['Thumbnail']
)
-
+ # print '----', workdict['Title']
+ # print ET.tostring(tree)
+
+print index_tree, type(index_tree)
write_html_file(index_tree, 'web/index.html')
print
print
diff --git a/web/2015-Artyom.html b/web/2015-Artyom.html
index 5e5d50e..9492786 100644
--- a/web/2015-Artyom.html
+++ b/web/2015-Artyom.html
@@ -2,7 +2,7 @@
- Title
+ Artyom-graduation-work
@@ -20,19 +20,19 @@
-
-
-
-
-
-
+
+
+
+
diff --git a/web/2015-Henk-Jelle_de_Groot.html b/web/2015-Henk-Jelle_de_Groot.html
index 4f980f1..eb690a0 100644
--- a/web/2015-Henk-Jelle_de_Groot.html
+++ b/web/2015-Henk-Jelle_de_Groot.html
@@ -2,7 +2,7 @@
- Title
+ U ntitled
@@ -20,21 +20,21 @@
-
-
-
-
-
-
+
+
+
+
diff --git a/web/2015-Lucia_Dossin.html b/web/2015-Lucia_Dossin.html
index 59d05cd..eb62720 100644
--- a/web/2015-Lucia_Dossin.html
+++ b/web/2015-Lucia_Dossin.html
@@ -2,7 +2,7 @@
- Title
+ Mina
@@ -20,19 +20,19 @@
-
-
-
-
-
-
+
+
+
+
-