Starting to fill in bits for detecting duplicate uploads
This commit is contained in:
parent
7ec57759fa
commit
f0381040dc
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from hashlib import sha1
|
||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
|
|
||||||
import flickrapi
|
import flickrapi
|
||||||
@ -15,6 +16,30 @@ def setup_flickr(api_key, api_secret):
|
|||||||
return flickr
|
return flickr
|
||||||
|
|
||||||
|
|
||||||
|
def get_photo_signature(flickr, photo_id):
|
||||||
|
info = flickr.photos_getInfo(photo_id=photo_id).find('photo')
|
||||||
|
exif = flickr.photos_getExif(photo_id=photo_id).find('photo')
|
||||||
|
|
||||||
|
if not info or not exif:
|
||||||
|
raise InvalidPhotoIdError(photo_id)
|
||||||
|
|
||||||
|
return [
|
||||||
|
info.get('originalformat'), info.find('owner').get('location'),
|
||||||
|
info.find('dates').get('taken')
|
||||||
|
] + sorted(
|
||||||
|
(e.get('label'), e.get('tag'), e.get('tagspace'), e.get('tagspaceid'),
|
||||||
|
e.find('raw').text) for e in exif.findall('exif')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_photo_sha1sum(flickr, photo_id):
|
||||||
|
return sha1(str(get_photo_signature(flickr, photo_id)))
|
||||||
|
|
||||||
|
|
||||||
def get_flickr_from_rc_file(rc_file=expanduser('~/.flickrscripts.json')):
|
def get_flickr_from_rc_file(rc_file=expanduser('~/.flickrscripts.json')):
|
||||||
rc_conf = json.load(open(rc_file))
|
rc_conf = json.load(open(rc_file))
|
||||||
return setup_flickr(rc_conf['APIKEY'], rc_conf['APISECRET'])
|
return setup_flickr(rc_conf['APIKEY'], rc_conf['APISECRET'])
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidPhotoIdError(ValueError):
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user