refining page creation

master
Castro0o 10 years ago
parent ff8b6f1631
commit c427d85712

File diff suppressed because one or more lines are too long

@ -89,7 +89,7 @@ def api_category(category, year): #Find all pages incategory and add to allworks
print '-------------' print '-------------'
print print
api_category('Graduation work', '2012') api_category('Graduation work', '2015')
json_allworks = open('allworks_mmdc.json', 'w') # save json json_allworks = open('allworks_mmdc.json', 'w') # save json
json.dump(allworks, json_allworks ) json.dump(allworks, json_allworks )

@ -48,68 +48,93 @@ def replace_video(content):
content = re.sub(video_exp, '', content) content = re.sub(video_exp, '', content)
return content, videos return content, videos
def create_workpage( allworks_dict, work_key, tree): # replace text content in dict with html nodes, holding the content def create_workpage( work, work_key, tree): # replace text content in dict with html nodes, holding the content
for key in allworks_dict.keys(): pprint.pprint( work)
for key in work.keys():
print work[key]
div_header = (tree.findall(".//div[@class='header']"))[0] div_header = (tree.findall(".//div[@class='header']"))[0]
div_body = (tree.findall(".//div[@class='body']"))[0] div_body = (tree.findall(".//div[@class='body']"))[0]
div_av = (tree.findall(".//div[@class='av']"))[0] div_av = (tree.findall(".//div[@class='av']"))[0]
# p = ET.Element('p')
# p.text = " oooo oooo oo"
# print 'ELEMENTS', ET.tostring(div_header)
# print 'ELEMENTS', ET.tostring(div_body)
# print 'ELEMENTS', ET.tostring(div_av)
# ET.SubElement(div_header, 'p' )
if key in ['Description', 'Extra']: if key in ['Description', 'Extra']:
mw_content = allworks_dict[key] mw_content = work[key]
if re.search(gallery_exp, mw_content): if re.search(gallery_exp, mw_content):
mw_content, gallery_imgs = replace_gallery(mw_content) mw_content, gallery_imgs = replace_gallery(mw_content)
allworks_dict['Images'] = gallery_imgs work['Images'] = gallery_imgs
for imgsrc in gallery_imgs: for imgsrc in gallery_imgs:
img_el = ET.SubElement(div_av, 'img', attrib={'src': imgsrc}) img_el = ET.SubElement(div_av, 'img', attrib={'src': imgsrc})
print 'IMG', ET.tostring(img_el)
elif re.search(video_exp, mw_content): elif re.search(video_exp, mw_content):
mw_content, videos = replace_video(mw_content) mw_content, videos = replace_video(mw_content)
allworks_dict['Video'] = videos work['Video'] = videos
for video in videos: for video in videos:
iframe_el = ET.SubElement(div_av, 'iframe', attrib={'src': video, 'width':'600px', 'height':'450px'}) iframe_el = ET.SubElement(div_av, 'iframe', attrib={'src': video, 'width':'600px', 'height':'450px'})
print 'VIDEO', ET.tostring(iframe_el) print 'VIDEO', ET.tostring(iframe_el)
allworks_dict[key] = pandoc2html( mw_content if key in allworks_dict.keys() else '' ) # convert to HTML
work_el = html5lib.parseFragment(allworks_dict[key], namespaceHTMLElements=False)
div_body.append( work_el )
print "****************************"
print ET.tostring(div_body)
print "****************************"
work[key] = pandoc2html( mw_content if key in work.keys() else '' ) # convert to HTML
text_el = html5lib.parseFragment(work[key], namespaceHTMLElements=False)
text_imgs = text_el.findall('.//img')
if text_imgs:
for img in text_imgs:
src = api_file_url(img.get('src'))
img.set('src', src)
print 'IMG', img, src
div_body.append( text_el )
elif key in ['Thumbnail']:
thumb = api_file_url(work[key])
img_el = ET.SubElement(div_av, 'img', attrib={'src': thumb})
elif key in ['Website']: elif key in ['Website']:
work_el = ET.SubElement(div_header, 'a', attrib={'href': allworks_dict[key], 'id':key}) work_el = ET.SubElement(div_header, 'a', attrib={'href': work[key], 'id':key})
work_el.text = 'LINK'#allworks_dict[key] work_el.text = work[key]
elif key in ['Title']: elif key in ['Title']:
work_el = ET.SubElement(div_header, 'h1', attrib={'id': key}) work_el = ET.SubElement(div_header, 'h1', attrib={'id': key})
work_el.text = (allworks_dict[key]).replace('_', ' ') work_el.text = (work[key]).replace('_', ' ')
elif key in ['Creator', 'Date', 'Bio']: elif key in ['Creator', 'Date', 'Bio']:
work_el =ET.SubElement(div_header, 'p', attrib={'id': key}) work_el =ET.SubElement(div_header, 'p', attrib={'id': key})
work_el.text = allworks_dict[key] work_el.text = work[key]
elif key in ['Thumbnail_url']:
print key
# ERROR - Thumbnail url is None
# work_el = ET.SubElement(div_header, 'img', attrib={'src': allworks_dict[key], 'id': key})
else:
work_el = None # remove keys with None value?
allworks_dict[key] = work_el
allworks_dict.pop('Thumbnail_url', None) #remove Thumbnail_url
pprint.pprint(allworks_dict)
# for key in work.keys():
# # p = ET.Element('p')
# # p.text = " oooo oooo oo"
# # print 'ELEMENTS', ET.tostring(div_header)
# # print 'ELEMENTS', ET.tostring(div_body)
# # print 'ELEMENTS', ET.tostring(div_av)
# # ET.SubElement(div_header, 'p' )
# print "****************************"
# print ET.tostring(div_body)
# print "****************************"
# # elif key in ['Thumbnail_url']:
# # print Thumbnail_url, work[key]
# elif key in ['Thumbnail_url']:
# print 'THUMBNAIL_URL', work[key]
# # ERROR - Thumbnail url is None
# # work_el = ET.SubElement(div_header, 'img', attrib={'src': work[key], 'id': key})
# else:
# work_el = None # remove keys with None value?
# work[key] = work_el
# work.pop('Thumbnail_url', None) #remove Thumbnail_url
# pprint.pprint(work)
def edit_index(filepath, json_allworks_dict): def edit_index(filepath, json_allworks_dict):
input_file = open(filepath, 'r') input_file = open(filepath, 'r')
tree = html5lib.parse(input_file, namespaceHTMLElements=False) tree = html5lib.parse(input_file, namespaceHTMLElements=False)
@ -122,20 +147,21 @@ def edit_index(filepath, json_allworks_dict):
worktemplate = open('web/work-template.html', 'r') worktemplate = open('web/work-template.html', 'r')
for key in json_allworks.keys(): for key in json_allworks.keys():
graduation_work=json_allworks[key] work=json_allworks[key]
graduation_work_title = (json_allworks[key]['Title']).encode('ascii', 'ignore') title = work['Title']
work_file = 'web/' + key + '-' + graduation_work_title + '.html' date = work['Date']
creator = (work['Creator'].encode('ascii', 'ignore')).replace(' ','_')
work_file = 'web/{}-{}-{}.html'.format(date, key, creator)
print work_file
work_tree = html5lib.parse(worktemplate, namespaceHTMLElements=False) work_tree = html5lib.parse(worktemplate, namespaceHTMLElements=False)
create_workpage(graduation_work, key, work_tree ) create_workpage(work, key, work_tree )
write_html_file(work_tree, work_file) write_html_file(work_tree, work_file)
print '----------'
# print ET.tostring(work_tree)
print graduation_work['Creator']
print graduation_work_title
print '----------'
### ISSSUES ### ISSSUES
# Error in thumbnail_url: it is None in JSON # Gallaries, Files, videos, in orginal places correct place
# Specific positions # Specificy positions in template
# rm <DOCUMENT_FRAGMENT> from pandoc output
# separate Extra and Description

@ -0,0 +1,16 @@
<!DOCTYPE HTML><html><head>
<meta charset="UTF-8">
<title></title> <!-- Work title will go to here -->
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div id="work">
<div class="header"><a href="https://en.wikipedia.org/wiki/Luther_Blissett_%28nom_de_plume%29" id="Website">https://en.wikipedia.org/wiki/Luther_Blissett_%28nom_de_plume%29</a><p id="Bio">Luther Blissett is a multiple-use name, an "open pop star" informally adopted and shared by hundreds of artists and activists all over Europe and the Americas since 1994. The pseudonym first appeared in Bologna, Italy, in mid-1994, when a number of cultural activists began using it for staging a series of urban and media pranks and to experiment with new forms of authorship and identity. From Bologna the multiple-use name spread to other European cities, such as Rome and London, as well as countries such as Germany, Spain, and Slovenia.[1] Sporadic appearances of Luther Blissett have been also noted in Canada, the United States, and Brazil.</p><h1 id="Title">Qq</h1><p id="Creator">Luther Blisset</p><p id="Date">2015</p></div><!--title, Creator, Date, Bio will go here -->
<div class="body"><DOCUMENT_FRAGMENT><p>The novel Q was written by four Bologna-based members of the LBP, as a final contribution to the project, and published in Italy in 1999. So far, it has been translated into English (British and American), Spanish, German, Dutch, French, Portuguese (Brazilian), Danish, Polish, Greek, Czech, Russian, Turkish, Basque and Korean. In August 2003 the book was nominated for the Guardian First Book Prize.</p>
</DOCUMENT_FRAGMENT><DOCUMENT_FRAGMENT><p>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 whereby knowledge workers and immaterial workers could organize and recognize themselves.[5] Thus, rather than being understood only as a media prankster and culture jammer, Luther Blissett became a positive mythic figure that was supposed to embody the very process of community and cross-media storytelling. Roberto Bui—one of the co-founders of the LBP and Wu Ming—explains the function of Luther Blissett and other radical folk heroes as mythmaking or mythopoesis<img alt="Quipu - a hybrid between octopus and rope " src="http://pzwiki.wdka.nl/mw-mediadesign/images/c/cc/Quipu.png" title="fig:Quipu - a hybrid between octopus and rope "><img alt="This is possibly a screen shot" src="http://pzwiki.wdka.nl/mw-mediadesign/images/3/38/Screen_Shot_2015-03-31_at_11.07.35.png" title="fig:This is possibly a screen shot"></p>
</DOCUMENT_FRAGMENT></div> <!-- Description, Extra will go here -->
<div class="av"><img src="http://pzwiki.wdka.nl/mw-mediadesign/images/8/85/Luther-blissett-300.jpg"><iframe height="450px" src="https://www.youtube.com/embed/WUXsLyX4u3M" width="600px"></iframe><iframe height="450px" src="https://www.youtube.com/embed/fg-IyA0jX6w" width="600px"></iframe></div> <!-- AV material (Thumbanail, gallery, video )will go here-->
</div>
</body></html>
Loading…
Cancel
Save