1
1
#!/usr/bin/python -utt
4
FLICKR_API_KEY = "f8aa9917a9ae5e44a87cae657924f42d"
5
FLICKR_API_SECRET = "3fbf7144be7eca28"
6
This tool tries to reproduce Flickr in Picasa.
8
Parts of "flickrfs" are reused. No additional ownership or copyright is
9
implied on those files.
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
19
SLEEP_BETWEEN_UPLOADS_SEC = 0
23
FLICKR_API_KEY, FLICKR_API_SECRET = "c4655b7c2d1e87d52db2d2375ec2ec59", "6c7e490f2b54667d"
15
25
__author__ = "Chad MILLER <software@chad.org>"
16
26
__license__ = "GPLv2 (details at http://www.gnu.org/licenses/licenses.html#GPL)"
130
140
local_filename_sent_flag = local_filename + "--picasa-upload.xml"
131
141
local_filename_temp = local_filename + "--picasa-upload.xml"
134
143
if os.path.exists(local_filename_sent_flag):
136
### clobber Picasa tags with Flickr tags
137
# for retry in range(3):
139
# cached_picasa_photoentry = gdata.photos.PhotoEntryFromString(open(local_filename_sent_flag).read())
141
# print "Failed to read file", local_filename_sent_flag
144
# if cached_picasa_photoentry.media.keywords.text:
145
# picasa_tags = set(cached_picasa_photoentry.media.keywords.text.decode("utf8").split(", "))
147
# picasa_tags = set()
148
# flickr_tags = set(flickr_photo.attrib[u'tags'].split())
150
# if picasa_tags != flickr_tags:
151
# print local_filename, ":",
153
# print picasa_tags, "->", flickr_tags
154
# #cached_picasa_photoentry.tags.text = " ".join(flickr_tags)
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)
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."
167
# elif http_code != 409:
168
# print http_code, http_status
169
# print "Failed to update", local_filename_sent_flag
171
# if current_document[0] != "<":
172
# print "Failed to update", local_filename_sent_flag
173
# print current_document
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."
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
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!
222
176
picasa_photoentry = gdata.photos.PhotoEntry()
178
## No idea what the API is doing here.
224
179
#picasa_photoentry.tags.text = html_parser.unescape(flickr_photo.attrib[u'tags'])
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())