def ExploreConnsAndRetData(self, U): if (self.nUsers >= self.nMaxNumOfUsrSupp): exit(0) # Limit exhausted, exit successfully. # Flickr API to retrieve list of Photos with UserID Photos = flickr.people_getPublicPhotos(U.id) if not Photos and not isinstance(U, str): self.log.debug("User: '******' has no photos") else: self.PopulatePhotosAndTags(U, Photos) # Storing the USERID and USERNAME into the database try: if not isinstance(U, str): self.insrtUsr(U.id, U.name) except: pass # Exploring friends' of the user if (self.nUsers < self.nMaxNumOfUsrSupp): FriendsList = flickr.contacts_getPublicList(U.id) if FriendsList: self.PopulateUserConns(U, FriendsList) if (self.Que.qsize() > 0) and (self.nUsers < self.nMaxNumOfUsrSupp): self.ExploreConnsAndRetData(self.Que.get())
def photos(self): if self.photo_list == None: self.photo_list = [] for p in flickr.people_getPublicPhotos(self.id, per_page=100): self.photo_list.append(Photo(p)) return self.photo_list
def search_by_user(name): user = flickr.people_findByUsername(name) photoList = flickr.people_getPublicPhotos(user.id) urls = [] for photo in photoList: urls.append(getURL(photo, 'Large', False)) for url in urls: print url
def get_photos(email,per_page=PER_PAGE): fuser = flickr.people_findByEmail(email) _out_log(u"已经连接用户【%s】的相片列表。" % fuser.username) photos = [] _out_log(u'正在获取相片列表...') try: photos = flickr.people_getPublicPhotos(fuser.id,per_page) except: _out_log(u'Flick 服务超时,下载失败.') return _down_files(photos)
def getCollectionFromFlickr(self,repView): coll = pim.ItemCollection(view = repView) if self.username: flickrUsername = flickr.people_findByUsername(self.username) flickrPhotos = flickr.people_getPublicPhotos(flickrUsername.id,10) coll.displayName = self.username elif self.tag: flickrPhotos = flickr.photos_search(tags=self.tag,per_page=10,sort="date-posted-asc") coll.displayName = self.tag.displayName self.sidebarCollection = coll for i in flickrPhotos: photoItem = getPhotoByFlickrID(repView, i.id) if photoItem is None: photoItem = FlickrPhoto(photo=i,view=repView,parent=coll) coll.add(photoItem) repView.commit()
def fillCollectionFromFlickr(self, view, n=16, apiKey=None): """ Fills the collection with photos from the flickr website. """ if apiKey: flickr.setLicense(apiKey) if self.userName: flickrUserName = flickr.people_findByUsername( self.userName.encode('utf8')) flickrPhotos = flickr.people_getPublicPhotos(flickrUserName.id, n) elif self.tag: flickrPhotos = flickr.photos_search(tags=self.tag, per_page=n, sort="date-posted-desc") else: assert (False, "we should have either a userName or tag") # flickrPhotosCollection is a collection of all FlickrPhotos. It has # an index named flickerIDIndex which indexes all the photos by # their flickrID which makes it easy to quickly lookup any photo by # index. flickrPhotosCollection = schema.ns('flickr', view).flickrPhotosCollection for flickrPhoto in flickrPhotos: """ If we've already downloaded a photo with this id use it instead. """ photoUUID = flickrPhotosCollection.findInIndex( 'flickrIDIndex', # name of Index 'exact', # require an exact match # compare function lambda uuid: cmp(flickrPhoto.id, view.findValue(uuid, 'flickrID'))) if photoUUID is None: photoItem = FlickrPhoto(photo=flickrPhoto, itsView=view) else: photoItem = view[photoUUID] self.add(photoItem) view.commit()
def photos(self): import flickr try: user = settings.FLICKR_USER flickr.API_KEY = settings.FLICKR_API_KEY except AttributeError: raise Http404 # Get first 12 photos for the user flickr_photos = flickr.people_getPublicPhotos(user, 12, 1) photos = [] #this loop is too slow. needs caching or a better library? for f in flickr_photos: photo = {} photo['url'] = f.getURL('Small', 'source') photo['link'] = f.getURL() photo['title'] = f._Photo__title photo['upload_date'] = datetime.datetime.fromtimestamp(float(f._Photo__dateposted)) photos.append(photo) return photos
def flickr(request): if not request.user.is_staff: raise Http404 import flickr try: user = settings.FLICKR_USER flickr.API_KEY = settings.FLICKR_API_KEY except AttributeError: return HttpResponse("You need to set <tt>FLICKR_USER</tt> and <tt>FLICKR_API_KEY</tt> in your settings file. <br />← <a href="/uploads/?textarea=%s">Back to all uploads.</a>" % (request.GET["textarea"],)) # Get first 12 photos for the user flickr_photos = flickr.people_getPublicPhotos(user, 12, 1) photos = [] #this loop is too slow. needs caching or a better library? for f in flickr_photos: photo = {} photo["url"] = f.getURL("Small", "source") photo["link"] = f.getURL() photo["title"] = f._Photo__title photo["upload_date"] = datetime.datetime.fromtimestamp(float(f._Photo__dateposted)) photos.append(photo) return render_to_response("upload/flickr.html", {"photos": photos, "textarea_id": request.GET["textarea"]}, context_instance=RequestContext(request))
def fillCollectionFromFlickr(self, view, n=16, apiKey=None): """ Fills the collection with photos from the flickr website. """ if apiKey: flickr.setLicense(apiKey) if self.userName: flickrUserName = flickr.people_findByUsername(self.userName.encode('utf8')) flickrPhotos = flickr.people_getPublicPhotos(flickrUserName.id, n) elif self.tag: flickrPhotos = flickr.photos_search(tags=self.tag, per_page=n, sort="date-posted-desc") else: assert(False, "we should have either a userName or tag") # flickrPhotosCollection is a collection of all FlickrPhotos. It has # an index named flickerIDIndex which indexes all the photos by # their flickrID which makes it easy to quickly lookup any photo by # index. flickrPhotosCollection = schema.ns('flickr', view).flickrPhotosCollection for flickrPhoto in flickrPhotos: """ If we've already downloaded a photo with this id use it instead. """ photoUUID = flickrPhotosCollection.findInIndex( 'flickrIDIndex', # name of Index 'exact', # require an exact match # compare function lambda uuid: cmp(flickrPhoto.id, view.findValue(uuid, 'flickrID'))) if photoUUID is None: photoItem = FlickrPhoto(photo=flickrPhoto, itsView=view) else: photoItem = view[photoUUID] self.add(photoItem) view.commit()
# Generate keys and FILL THESE OUT # http://www.flickr.com/services/apps/create/noncommercial/ flickr.API_KEY = '' flickr.API_SECRET = '' # find this on http://www.flickr.com/account # it's whatever it says next to "Your screen name" me = flickr.people_findByUsername("") page = 1 total_photos = found_photos = 0 while 1: try: photos = flickr.people_getPublicPhotos(me.id, 100, page) for photo in photos: total_photos += 1 # skip if we already have this photo have_photo = os.path.exists("%s_%s_%s_o.jpg" % (photo.server, photo.id, photo.secret)) if not have_photo: data = urllib.urlretrieve("http://static.flickr.com/%s/%s_%s_o.jpg" % (photo.server, photo.id, photo.secret), "%s_%s_%s_o.jpg" % (photo.server, photo.id, photo.secret)) print "save %s" % photo.title found_photos += 1 page += 1 except AttributeError: break # This shouldn't happen! print "Found %s photos, saved %s new photos" % (total_photos, found_photos)