|
|
|
@ -123,14 +123,17 @@ def main():
|
|
|
|
|
#wget file
|
|
|
|
|
if original_name != img_name: #the image is an old version, download using /archive/ path in server
|
|
|
|
|
os.system('wget -c "http://upload.wikimedia.org/wikipedia/commons/archive/%s/%s/%s" -O "%s/%s"' % (md5hash[0], md5hash[0:2], img_name_quoted, savepath, img_saved_as_))
|
|
|
|
|
if not os.path.getsize('%s/%s' % (savepath, img_saved_as_)): #empty file?...
|
|
|
|
|
#probably false 20101005024534! begining like this http://commons.wikimedia.org/wiki/File:20041028210012!Pilar.jpg
|
|
|
|
|
#ok, restore original_name to ! version and recalculate md5 and other variables that use original_name as source
|
|
|
|
|
original_name = img_name
|
|
|
|
|
original_name_ = re.sub(r'"', r'\"', re.sub(r' ', r'_', original_name.encode('utf-8')))
|
|
|
|
|
md5hash = md5(re.sub(' ', '_', original_name.encode("utf-8"))).hexdigest()
|
|
|
|
|
#redownload, now without /archive/ subpath
|
|
|
|
|
os.system('wget -c "http://upload.wikimedia.org/wikipedia/commons/%s/%s/%s" -O "%s/%s"' % (md5hash[0], md5hash[0:2], img_name_quoted, savepath, img_saved_as_))
|
|
|
|
|
try:
|
|
|
|
|
if not os.path.getsize('%s/%s' % (savepath, img_saved_as_)): #empty file?...
|
|
|
|
|
#probably false 20101005024534! begining like this http://commons.wikimedia.org/wiki/File:20041028210012!Pilar.jpg
|
|
|
|
|
#ok, restore original_name to ! version and recalculate md5 and other variables that use original_name as source
|
|
|
|
|
original_name = img_name
|
|
|
|
|
original_name_ = re.sub(r'"', r'\"', re.sub(r' ', r'_', original_name.encode('utf-8')))
|
|
|
|
|
md5hash = md5(re.sub(' ', '_', original_name.encode("utf-8"))).hexdigest()
|
|
|
|
|
#redownload, now without /archive/ subpath
|
|
|
|
|
os.system('wget -c "http://upload.wikimedia.org/wikipedia/commons/%s/%s/%s" -O "%s/%s"' % (md5hash[0], md5hash[0:2], img_name_quoted, savepath, img_saved_as_))
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
os.system('wget -c "http://upload.wikimedia.org/wikipedia/commons/%s/%s/%s" -O "%s/%s"' % (md5hash[0], md5hash[0:2], img_name_quoted, savepath, img_saved_as_))
|
|
|
|
|
|
|
|
|
|