forked from mhl/flickr-checksums
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-not-uploaded.py
executable file
·61 lines (53 loc) · 2.01 KB
/
find-not-uploaded.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python2.7
# Copyright 2009 Mark Longair
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# You might use this, for example, as:
#
# find ~/photos/ -name '*.jpg' -print0 | xargs -0 ./find-not-uploaded.py
import os
import sys
import re
import xml
import tempfile
from subprocess import call, Popen, PIPE
from optparse import OptionParser
from common import checksum
from flickr_common import authenticate_to_flickr
from flickr_checksum_lib import search_for_checksum
from flickrapi.shorturl import url as short_url
all_filenames = sys.argv[1:]
parser = OptionParser(usage="Usage: %prog [OPTION] [FILE]...")
parser.add_option('-v', '--verbose', dest='verbose', default=False,
action='store_true',
help='Turn on verbose output')
options, args = parser.parse_args()
flickr = authenticate_to_flickr()
for filename in args:
md5sum = checksum(filename, "md5")
if options.verbose:
print "filename was: "+filename
print " with md5sum: "+md5sum
existing = search_for_checksum(flickr, md5=md5sum)
if 1 == len(existing):
if options.verbose:
print " ... already uploaded"
print short_url(existing[0].attrib['id'])
elif len(existing) > 1:
if options.verbose:
print " ... multiple copies uploaded"
else:
if options.verbose:
print " ... not uploaded"
else:
print filename