~cmiller/+junk/copy-flickr-to-picasa

« back to all changes in this revision

Viewing changes to copy-flickr-to-picasa

  • Committer: C Miller
  • Date: 2011-08-02 11:44:45 UTC
  • Revision ID: bzrdev@chad.org-20110802114445-080qrtgfoa92mb6w
Clean up.  Prepare for release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -utt
2
2
 
3
 
 
4
 
FLICKR_API_KEY = "f8aa9917a9ae5e44a87cae657924f42d"
5
 
FLICKR_API_SECRET = "3fbf7144be7eca28"
 
3
"""
 
4
copy-flickr-to-picasa
 
5
 
 
6
This tool tries to reproduce Flickr in Picasa.
 
7
 
 
8
Parts of "flickrfs" are reused.  No additional ownership or copyright is
 
9
implied on those files.
 
10
"""
 
11
 
 
12
# You may change these
6
13
BROWSERNAME = "/usr/bin/x-www-browser"
7
14
DEST_ALBUM_NAME_PUBLIC = u"From Flickr"
8
15
DEST_ALBUM_NAME_ONLY_ME = u"From Flickr, private"
9
16
DEST_ALBUM_NAME_ONLY_FRIENDS = u"From Flickr, friends"
10
17
DEST_ALBUM_NAME_ONLY_FAMILY = u"From Flickr, family"
11
18
DEST_ALBUM_NAME_ONLY_FAMILY_AND_FRIENDS = u"From Flickr, family and friends"
12
 
SLEEP_BETWEEN_UPLOADS_SEC = 3
13
 
 
 
19
SLEEP_BETWEEN_UPLOADS_SEC = 0
 
20
 
 
21
 
 
22
# Don't change these
 
23
FLICKR_API_KEY, FLICKR_API_SECRET = "c4655b7c2d1e87d52db2d2375ec2ec59", "6c7e490f2b54667d"
14
24
 
15
25
__author__ =  "Chad MILLER <software@chad.org>"
16
26
__license__ = "GPLv2 (details at http://www.gnu.org/licenses/licenses.html#GPL)"
69
79
NSID = transfl.getUserId()
70
80
if NSID is None:
71
81
  log.error("Initialization:Can't retrieve user information")
72
 
  sys.exit(-1)
 
82
  sys.exit(1)
73
83
 
74
84
 
75
85
 
130
140
        local_filename_sent_flag = local_filename + "--picasa-upload.xml"
131
141
        local_filename_temp = local_filename + "--picasa-upload.xml"
132
142
 
133
 
 
134
143
        if os.path.exists(local_filename_sent_flag):
135
 
 
136
 
### clobber Picasa tags with Flickr tags
137
 
#            for retry in range(3):
138
 
#                try:
139
 
#                    cached_picasa_photoentry = gdata.photos.PhotoEntryFromString(open(local_filename_sent_flag).read())
140
 
#                except:
141
 
#                    print "Failed to read file", local_filename_sent_flag
142
 
#                    sys.exit(2)
143
 
#
144
 
#                if cached_picasa_photoentry.media.keywords.text:
145
 
#                    picasa_tags = set(cached_picasa_photoentry.media.keywords.text.decode("utf8").split(", "))
146
 
#                else:
147
 
#                    picasa_tags = set()
148
 
#                flickr_tags = set(flickr_photo.attrib[u'tags'].split())
149
 
#
150
 
#                if picasa_tags != flickr_tags:
151
 
#                    print local_filename, ":",
152
 
#                    if picasa_tags:
153
 
#                        print picasa_tags, "->", flickr_tags
154
 
#                    #cached_picasa_photoentry.tags.text = " ".join(flickr_tags)
155
 
#
156
 
#                    if not cached_picasa_photoentry.media.keywords:
157
 
#                        cached_picasa_photoentry.media.keywords = gdata.media.Keywords()
158
 
#                    cached_picasa_photoentry.media.keywords.text = ",".join(flickr_tags)
159
 
#
160
 
#                    try:
161
 
#                        picasa_photo = gd_client.UpdatePhotoMetadata(cached_picasa_photoentry)
162
 
#                    except gdata.photos.service.GooglePhotosException, ex:
163
 
#                        http_code, http_status, current_document = ex.args
164
 
#                        if http_code == 404:
165
 
#                            print "File on on Picasa.  Assuming intentionally removed."
166
 
#                            break
167
 
#                        elif http_code != 409:
168
 
#                            print http_code, http_status
169
 
#                            print "Failed to update", local_filename_sent_flag
170
 
#                            raise
171
 
#                        if current_document[0] != "<":
172
 
#                            print "Failed to update", local_filename_sent_flag
173
 
#                            print current_document
174
 
#                            sys.exit(1)
175
 
#                            
176
 
#                        print "Failed to update", local_filename_sent_flag
177
 
#                        with open(local_filename_sent_flag+"-", "w") as flag:
178
 
#                            flag.write(current_document)
179
 
#                        os.rename(local_filename_sent_flag+"-", local_filename_sent_flag)
180
 
#                        print "Wrote new cache file.  Retrying."
181
 
#                        continue
182
 
#
183
 
#                    with open(local_filename_sent_flag+"-", "w") as flag:
184
 
#                        flag.write(str(picasa_photo))
185
 
#                    os.rename(local_filename_sent_flag+"-", local_filename_sent_flag)
186
 
#                    print "Updated tags.", picasa_photo.media.keywords.text
187
 
 
188
144
            continue
189
145
 
190
 
 
191
 
 
192
146
        if flickr_photo.attrib[u'media'] != u'photo':
193
147
            print "Skipping", flickr_photo.attrib[u'media'].encode("utf8"), local_filename
194
 
            # Picasa just recently added video support.  API lags behind it.  :(
 
148
            # Picasa just recently added video support.  API lags behind it.  TODO!
195
149
            success = False
196
150
            continue
197
151
 
221
175
 
222
176
        picasa_photoentry = gdata.photos.PhotoEntry()
223
177
 
 
178
        ## No idea what the API is doing here.
224
179
        #picasa_photoentry.tags.text = html_parser.unescape(flickr_photo.attrib[u'tags'])
225
 
 
226
180
        if not picasa_photoentry.media.keywords:
227
181
          picasa_photoentry.media.keywords = gdata.media.Keywords()
228
182
          picasa_photoentry.media.keywords.text = ",".join(html_parser.unescape(flickr_photo.attrib[u'tags']).split())