|
|
|
@ -19,8 +19,6 @@ img_exp=re.compile('(File:|Image:)((.*?)\.(gif|jpg|jpeg|png))(?=\||File:|Image:|
|
|
|
|
|
video_exp=re.compile('\{\{(.*?)\|(.*?)\}\}')
|
|
|
|
|
|
|
|
|
|
def replace_gallery(content):
|
|
|
|
|
# from <gallery>.*</gallery> imgs, return list of img ET elements
|
|
|
|
|
# replace <gallery>.*</gallery> with ''
|
|
|
|
|
gallery_imgs = []
|
|
|
|
|
gallery_found = re.findall(gallery_exp, content)
|
|
|
|
|
content = re.sub(gallery_exp, '', content)
|
|
|
|
@ -30,6 +28,9 @@ def replace_gallery(content):
|
|
|
|
|
imgfile = imgfile[1]
|
|
|
|
|
imgsrc = api_file_url(imgfile) # search for original image
|
|
|
|
|
gallery_imgs.append(imgsrc)
|
|
|
|
|
print 'gallery_imgs', gallery_imgs
|
|
|
|
|
# from <gallery>.*</gallery> imgs, return list of img ET elements
|
|
|
|
|
# replace <gallery>.*</gallery> with ''
|
|
|
|
|
return content, gallery_imgs
|
|
|
|
|
|
|
|
|
|
def replace_video(content):
|
|
|
|
@ -45,6 +46,9 @@ def replace_video(content):
|
|
|
|
|
video_src="https://player.vimeo.com/video/" + video_hash
|
|
|
|
|
if video_src:
|
|
|
|
|
videos.append(video_src)
|
|
|
|
|
iframe = "<iframe src='{}' width='600px' height='450px'></iframe>".format(video_src)
|
|
|
|
|
# content = re.sub(video_exp, ' iframe ', content)
|
|
|
|
|
else:
|
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
|
return content, videos
|
|
|
|
|
|
|
|
|
@ -59,23 +63,23 @@ def create_workpage( work, work_key, tree): # replace text content in dict with
|
|
|
|
|
|
|
|
|
|
if key in ['Description', 'Extra']:
|
|
|
|
|
mw_content = work[key]
|
|
|
|
|
if re.search(gallery_exp, mw_content):
|
|
|
|
|
mw_content, gallery_imgs = replace_gallery(mw_content)
|
|
|
|
|
work['Images'] = gallery_imgs
|
|
|
|
|
for imgsrc in gallery_imgs:
|
|
|
|
|
img_el = ET.SubElement(div_av, 'img', attrib={'src': imgsrc})
|
|
|
|
|
elif re.search(video_exp, mw_content):
|
|
|
|
|
mw_content, videos = replace_video(mw_content)
|
|
|
|
|
work['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)
|
|
|
|
|
# if re.search(gallery_exp, mw_content):
|
|
|
|
|
# # replace_gallery must replace the gallery inline
|
|
|
|
|
# mw_content, gallery_imgs = replace_gallery(mw_content)
|
|
|
|
|
# work['Images'] = gallery_imgs
|
|
|
|
|
# for imgsrc in gallery_imgs:
|
|
|
|
|
# img_el = ET.SubElement(div_av, 'img', attrib={'src': imgsrc})
|
|
|
|
|
# elif re.search(video_exp, mw_content):
|
|
|
|
|
# mw_content, videos = replace_video(mw_content)
|
|
|
|
|
# work['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)
|
|
|
|
|
|
|
|
|
|
print '--------------'
|
|
|
|
|
print 'mw_content', mw_content
|
|
|
|
|
print '--------------'
|
|
|
|
|
x=mw_content
|
|
|
|
|
html_content = pandoc2html( x if key in work.keys() else '') # convert to HTML
|
|
|
|
|
html_content = pandoc2html( mw_content if key in work.keys() else '') # convert to HTML
|
|
|
|
|
print 'html_content', html_content
|
|
|
|
|
document_el = html5lib.parse(html_content, namespaceHTMLElements=False)#ET.fromstring(html_content)
|
|
|
|
|
print ET.tostring(document_el)
|
|
|
|
@ -89,14 +93,11 @@ def create_workpage( work, work_key, tree): # replace text content in dict with
|
|
|
|
|
div_body.append(el)
|
|
|
|
|
|
|
|
|
|
imgs = document_el.findall('.//img')
|
|
|
|
|
if imgs:
|
|
|
|
|
for img in imgs:
|
|
|
|
|
src = api_file_url(img.get('src'))
|
|
|
|
|
img.set('src', src)
|
|
|
|
|
print 'IMG', img, src
|
|
|
|
|
|
|
|
|
|
# div_body.append( document_el )
|
|
|
|
|
# print 'div_body', ET.tostring(div_body)
|
|
|
|
|
# if imgs:
|
|
|
|
|
# for img in imgs:
|
|
|
|
|
# src = api_file_url(img.get('src'))
|
|
|
|
|
# img.set('src', src)
|
|
|
|
|
# print 'IMG', img, src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif key in ['Thumbnail']:
|
|
|
|
@ -116,18 +117,6 @@ def create_workpage( work, work_key, tree): # replace text content in dict with
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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 "****************************"
|
|
|
|
@ -171,6 +160,11 @@ for key in json_allworks.keys():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ISSSUES
|
|
|
|
|
# pandoc mw->HTML NOT WORKING
|
|
|
|
|
# sub gallery/videos with corresponding elements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Gallaries, Files, videos, in orginal places correct place
|
|
|
|
|
# Specificy positions in template
|
|
|
|
|
# insert <p> into <div class="body">
|
|
|
|
|