Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
.settings
.DS_Store
*.pyc
.idea

44 changes: 43 additions & 1 deletion uploadr/uploadr.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import urllib2
import webbrowser
import xmltramp
import urllib

#
##
Expand Down Expand Up @@ -120,6 +121,10 @@ def __init__( self ):
"""
self.token = self.getCachedToken()

if args.search_dups:
self.isDuplicate = self.isFlickrDuplicate
else:
self.isDuplicate = lambda image: self.uploaded.has_key(image)


def signCall( self, data):
Expand Down Expand Up @@ -337,7 +342,7 @@ def uploadImage( self, image ):
"""

success = False
if ( not self.uploaded.has_key( image ) ):
if not self.isDuplicate(image):
print("Uploading " + image + "...")
try:
photo = ('photo', image, open(image,'rb').read())
Expand Down Expand Up @@ -370,6 +375,8 @@ def uploadImage( self, image ):
else :
print("Problem:")
self.reportError( res )
except KeyboardInterrupt:
sys.exit(1)
except:
print(str(sys.exc_info()))
return success
Expand Down Expand Up @@ -458,6 +465,39 @@ def getResponse( self, url ):
xml = urllib2.urlopen( url ).read()
return xmltramp.parse( xml )

def isFlickrDuplicate(self, image):
"""
flickr.photos.search

Searches the flickr service for an existing title.
"""
if ( self.token == None ):
return False
else :
d = {
api.token : str(self.token) ,
api.method : "flickr.photos.search",
}
search = os.path.basename(image).split('.')[0]
# Define search text
d['text'] = urllib.quote_plus(search)
# Only search user's own photos
d['user_id'] = 'me'

sig = self.signCall( d )
url = self.urlGen( api.rest, d, sig )
try:
xml = urllib2.urlopen( url ).read()
print xml
# The returned XML contains the original name if found
if xml.find(search) == -1:
return False
else:
print "Duplicate: ", search
return True
except:
print(str(sys.exc_info()))
return False

def run( self ):
""" run
Expand All @@ -480,6 +520,8 @@ def run( self ):
help='Space-separated tags for uploaded images')
parser.add_argument('-r', '--drip-feed', action='store_true',
help='Wait a bit between uploading individual images')
parser.add_argument('-s', '--search-dups', action='store_true',
help='Check Flickr for duplicate title before uploading')
args = parser.parse_args()

flick = Uploadr()
Expand Down