|
|
@ -8,6 +8,8 @@ sid = '1234'
|
|
|
|
useragent = "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"
|
|
|
|
useragent = "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"
|
|
|
|
endpoint = "http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&"
|
|
|
|
endpoint = "http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# API MODULES
|
|
|
|
# API MODULES
|
|
|
|
def api_request(action, pagename): #get page: content, metadata, images, imageifnp
|
|
|
|
def api_request(action, pagename): #get page: content, metadata, images, imageifnp
|
|
|
|
print 'API REQUEST'
|
|
|
|
print 'API REQUEST'
|
|
|
@ -157,20 +159,38 @@ def img_fullurl(parent):
|
|
|
|
img.set('src', fullurl)
|
|
|
|
img.set('src', fullurl)
|
|
|
|
# fileurl = api_request(src, endpoint)# find url of file
|
|
|
|
# fileurl = api_request(src, endpoint)# find url of file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gallery_exp=re.compile('<gallery>.*?</gallery>', re.S)
|
|
|
|
|
|
|
|
imgfile_exp=re.compile('(File:(.*?\.(gif|jpg|jpeg|png)))')# (?=File:|<\/gallery>)')
|
|
|
|
|
|
|
|
img_exp=re.compile('(File:|Image:)((.*?)\.(gif|jpg|jpeg|png))(?=\||File:|Image:|<\/gallery>)', re.I)
|
|
|
|
|
|
|
|
video_exp=re.compile('\{\{(.*?)\|(.*?)\}\}')
|
|
|
|
|
|
|
|
|
|
|
|
def replace_gallery(content):
|
|
|
|
def replace_gallery(content):
|
|
|
|
gallery_imgs = []
|
|
|
|
gallery_imgs = []
|
|
|
|
gallery_found = re.findall(gallery_exp, content)
|
|
|
|
gallery_found = re.findall(gallery_exp, content)
|
|
|
|
content = re.sub(gallery_exp, '', content)
|
|
|
|
|
|
|
|
for gallery in gallery_found: # in case there is more than 1 <gallery>
|
|
|
|
for gallery in gallery_found: # in case there is more than 1 <gallery>
|
|
|
|
allfiles =re.findall(img_exp, gallery)
|
|
|
|
allfiles =re.findall(imgfile_exp, gallery)
|
|
|
|
|
|
|
|
print 'ALLFILES', allfiles
|
|
|
|
for imgfile in allfiles:
|
|
|
|
for imgfile in allfiles:
|
|
|
|
imgfile = imgfile[1]
|
|
|
|
imgfile = imgfile[1]
|
|
|
|
imgsrc = api_file_url(imgfile) # search for original image
|
|
|
|
#imgsrc = imgfile
|
|
|
|
|
|
|
|
imgsrc = api_file_url(imgfile) # seaarch for original image
|
|
|
|
|
|
|
|
newimg = ''
|
|
|
|
gallery_imgs.append(imgsrc)
|
|
|
|
gallery_imgs.append(imgsrc)
|
|
|
|
print 'gallery_imgs', gallery_imgs
|
|
|
|
print 'GALLERY_IMGS', gallery_imgs
|
|
|
|
# from <gallery>.*</gallery> imgs, return list of img ET elements
|
|
|
|
|
|
|
|
# replace <gallery>.*</gallery> with ''
|
|
|
|
ungallery_imgs = " ".join(gallery_imgs)
|
|
|
|
return content, gallery_imgs
|
|
|
|
print 'ungallery_imgs', ungallery_imgs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content = re.sub(gallery_exp, ungallery_imgs, content)
|
|
|
|
|
|
|
|
print 'images content', content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## BUG: Images are being replaced as <a>
|
|
|
|
|
|
|
|
# EG: <a class="uri" href="File:Mb-WordNet-tour-version2-08.png">File:Mb-WordNet-tour-version2-08.png</a> <a class="uri" href="File:Labanotation1.jpg">File:Labanotation1.jpg</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
def replace_video(content):
|
|
|
|
def replace_video(content):
|
|
|
|
videos = []
|
|
|
|
videos = []
|
|
|
@ -185,12 +205,13 @@ def replace_video(content):
|
|
|
|
video_src="https://player.vimeo.com/video/" + video_hash
|
|
|
|
video_src="https://player.vimeo.com/video/" + video_hash
|
|
|
|
if video_src:
|
|
|
|
if video_src:
|
|
|
|
videos.append(video_src)
|
|
|
|
videos.append(video_src)
|
|
|
|
iframe = "<iframe src='{}' width='600px' height='450px'></iframe>".format(video_src)
|
|
|
|
iframe = "<iframe src='{}' width='600px' height='450px'> </iframe>".format(video_src)
|
|
|
|
# content = re.sub(video_exp, ' iframe ', content)
|
|
|
|
content = re.sub(video_exp, iframe, content)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Video Replacement: problem with video: iframe is placed inside <p> . It shouldn't
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## replace gallery - not yet there
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|