|
|
@ -29,8 +29,7 @@ def replace_gallery(content):
|
|
|
|
for imgfile in allfiles:
|
|
|
|
for imgfile in allfiles:
|
|
|
|
imgfile = imgfile[1]
|
|
|
|
imgfile = imgfile[1]
|
|
|
|
imgsrc = api_file_url(imgfile) # search for original image
|
|
|
|
imgsrc = api_file_url(imgfile) # search for original image
|
|
|
|
img_el = ET.Element('img', attrib={'src': imgsrc})
|
|
|
|
gallery_imgs.append(imgsrc)
|
|
|
|
gallery_imgs.append(img_el)
|
|
|
|
|
|
|
|
return content, gallery_imgs
|
|
|
|
return content, gallery_imgs
|
|
|
|
|
|
|
|
|
|
|
|
def replace_video(content):
|
|
|
|
def replace_video(content):
|
|
|
@ -45,8 +44,7 @@ def replace_video(content):
|
|
|
|
elif (video_provider.lower()) == 'vimeo':
|
|
|
|
elif (video_provider.lower()) == 'vimeo':
|
|
|
|
video_src="https://player.vimeo.com/video/" + video_hash
|
|
|
|
video_src="https://player.vimeo.com/video/" + video_hash
|
|
|
|
if video_src:
|
|
|
|
if video_src:
|
|
|
|
iframe_el = ET.Element('iframe', attrib={'src':video_src, 'width':'600px', 'height':'450px'})
|
|
|
|
videos.append(video_src)
|
|
|
|
videos.append(iframe_el)
|
|
|
|
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
return content, videos
|
|
|
|
return content, videos
|
|
|
|
|
|
|
|
|
|
|
@ -55,48 +53,62 @@ def create_workpage( allworks_dict, work_key, tree): # replace text content in d
|
|
|
|
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 = allworks_dict[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
|
|
|
|
allworks_dict['Images'] = gallery_imgs
|
|
|
|
|
|
|
|
for imgsrc in gallery_imgs:
|
|
|
|
|
|
|
|
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
|
|
|
|
allworks_dict['Video'] = videos
|
|
|
|
|
|
|
|
for video in videos:
|
|
|
|
|
|
|
|
iframe_el = ET.SubElement(div_av, 'iframe', attrib={'src': video, 'width':'600px', 'height':'450px'})
|
|
|
|
|
|
|
|
print 'VIDEO', ET.tostring(iframe_el)
|
|
|
|
|
|
|
|
|
|
|
|
allworks_dict[key] = pandoc2html( mw_content if key in allworks_dict.keys() else '' ) # convert to HTML
|
|
|
|
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)
|
|
|
|
work_el = html5lib.parseFragment(allworks_dict[key], namespaceHTMLElements=False)
|
|
|
|
|
|
|
|
|
|
|
|
div_body.append( work_el )
|
|
|
|
div_body.append( work_el )
|
|
|
|
|
|
|
|
|
|
|
|
print "****************************"
|
|
|
|
print "****************************"
|
|
|
|
print ET.tostring(div_body)
|
|
|
|
print ET.tostring(div_body)
|
|
|
|
print "****************************"
|
|
|
|
print "****************************"
|
|
|
|
|
|
|
|
|
|
|
|
elif key in ['Website']:
|
|
|
|
elif key in ['Website']:
|
|
|
|
work_el = ET.Element('a', attrib={'href': allworks_dict[key], 'id':key})
|
|
|
|
work_el = ET.SubElement(div_header, 'a', attrib={'href': allworks_dict[key], 'id':key})
|
|
|
|
work_el.text = 'LINK'#allworks_dict[key]
|
|
|
|
work_el.text = 'LINK'#allworks_dict[key]
|
|
|
|
elif key in ['Title']:
|
|
|
|
elif key in ['Title']:
|
|
|
|
work_el = ET.Element('h1', attrib={'id': key})
|
|
|
|
work_el = ET.SubElement(div_header, 'h1', attrib={'id': key})
|
|
|
|
work_el.text = allworks_dict[key]
|
|
|
|
work_el.text = (allworks_dict[key]).replace('_', ' ')
|
|
|
|
|
|
|
|
|
|
|
|
# typeerror: must be Element, not Element
|
|
|
|
|
|
|
|
# div_header.append(work_el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif key in ['Creator', 'Date', 'Bio']:
|
|
|
|
elif key in ['Creator', 'Date', 'Bio']:
|
|
|
|
work_el = ET.Element('p', attrib={'id': key})
|
|
|
|
work_el =ET.SubElement(div_header, 'p', attrib={'id': key})
|
|
|
|
work_el.text = allworks_dict[key]
|
|
|
|
work_el.text = allworks_dict[key]
|
|
|
|
elif key in ['Thumbnail']:
|
|
|
|
|
|
|
|
work_el = ET.Element('img', attrib={'src': allworks_dict[key], 'id': key})
|
|
|
|
elif key in ['Thumbnail_url']:
|
|
|
|
print ET.tostring(work_el)
|
|
|
|
print key
|
|
|
|
|
|
|
|
# ERROR - Thumbnail url is None
|
|
|
|
|
|
|
|
# work_el = ET.SubElement(div_header, 'img', attrib={'src': allworks_dict[key], 'id': key})
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
work_el = None # remove keys with None value?
|
|
|
|
work_el = None # remove keys with None value?
|
|
|
|
allworks_dict[key] = work_el
|
|
|
|
allworks_dict[key] = work_el
|
|
|
|
allworks_dict.pop('Thumbnail_url', None) #remove Thumbnail_url
|
|
|
|
allworks_dict.pop('Thumbnail_url', None) #remove Thumbnail_url
|
|
|
|
pprint.pprint(allworks_dict)
|
|
|
|
pprint.pprint(allworks_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def edit_index(filepath, json_allworks_dict):
|
|
|
|
def edit_index(filepath, json_allworks_dict):
|
|
|
|
input_file = open(filepath, 'r')
|
|
|
|
input_file = open(filepath, 'r')
|
|
|
@ -122,3 +134,8 @@ for key in json_allworks.keys():
|
|
|
|
print graduation_work_title
|
|
|
|
print graduation_work_title
|
|
|
|
|
|
|
|
|
|
|
|
print '----------'
|
|
|
|
print '----------'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ISSSUES
|
|
|
|
|
|
|
|
# Error in thumbnail_url: it is None in JSON
|
|
|
|
|
|
|
|
# Specific positions
|
|
|
|