Skip to content

Commit

Permalink
Do-Not-Load-Duplicates: 8th code Alfa Testing
Browse files Browse the repository at this point in the history
- fixed replacePhoto to use fileobj instead of filename to cater for unicode file names.
- still does not fully prevent loading duplicates (same title, md5/checksum, setname) which namely occur due to errors. In princicple many loading up errors are being avoided anyhow!
- under testing.
  • Loading branch information
oPromessa committed Nov 12, 2017
1 parent 8ad0889 commit b51a704
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions uploadr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ def uploadFile(self, lock, file):
if isThisStringUnicode(setName) \
else setName))
try:
# CODING: Is This sequence/assignment to photo being used?
if isThisStringUnicode(file):
photo = ('photo', file.encode('utf-8'),
open(file, 'rb').read())
Expand Down Expand Up @@ -1870,6 +1871,7 @@ def replacePhoto(self, lock, file, file_id,
con = current DB connection
"""

# CODING: Flickr does not allow to replace videos.
global nuflickr

if (args.dry_run is True):
Expand All @@ -1887,18 +1889,17 @@ def replacePhoto(self, lock, file, file_id,

success = False
try:
if isThisStringUnicode(file):
photo = ('photo',
file.encode('utf-8'),
open(file, 'rb').read())
else:
photo = ('photo', file, open(file, 'rb').read())

res = None
res_add_tag = None
res_get_info = None
replaceResp = None

# photo would be a FileObj.
# nuflickr.replace accepts both a filename and a file object.
# when using filenames wiht unicode characters
# - the flickrapi seems to fail with filename
# - will try with FileObj and filename='dummy'
photo = open(file.encode('utf-8'), 'rb')\
if isThisStringUnicode(file)\
else open(file, 'rb')
logging.debug('photo:[{!s}] type(photo):[{!s}]'
.format(photo, type(photo)))

for x in range(0, MAX_UPLOAD_ATTEMPTS):
res = None
res_add_tag = None
Expand All @@ -1915,11 +1916,17 @@ def replacePhoto(self, lock, file, file_id,
x,
MAX_UPLOAD_ATTEMPTS))

# Use fileobj.
# replaceResp = nuflickr.replace(
# filename=file,
# fileobj=FileWithCallback(file, callback),
# photo_id=file_id
# )
replaceResp = nuflickr.replace(
filename=file,
filename='dummy',
fileobj=FileWithCallback(file, callback),
photo_id=file_id
)
)
logging.info('replaceResp: ')
logging.info(xml.etree.ElementTree.tostring(
replaceResp,
Expand Down

0 comments on commit b51a704

Please sign in to comment.