def GetFlickrImagesFromPhotoSet(self, flickr, userinfo): list = [] sets = flickr.photosets_getList(user_id=userinfo.flickr_id) #这里每轮最多10张 for photo in flickr.walk_set(photoset_id=userinfo.flickr_browse_setid, per_page='10'): photo_id = photo.attrib['id'] title = photo.attrib['title'] farm = photo.attrib['farm'] server = photo.attrib['server'] secret = photo.attrib['secret'] logging.info("get %s"% photo_id) self.response.out.write("get %s<br/>"% photo_id) photo = FlickrRecord.gql('WHERE photo_id=:1', photo_id).get() #photo = None if photo: logging.info("photo exist ") self.response.out.write("photo exist <br/>") continue url = "http://farm%s.staticflickr.com/%s/%s_%s.jpg"%(farm, server, photo_id, secret) link = "http://www.flickr.com/photos/%s/%s" % (userinfo.flickr_id, photo_id) e = FlickrRecord() e.photo_id = photo_id e.title = title e.url = url e.link = link list.append(e) return list
def GetFlickrImagesFromPhotoTag(self, flickr, userinfo, tags): list = [] #url = "http://api.flickr.com/services/feeds/photos_public.gne?id="+flickr_id+"&lang=en-us&format=rss_200" url = "http://api.flickr.com/services/feeds/photos_public.gne?id="+userinfo.flickr_id+"&lang=en-us&format=json" if tags : url = url +"&tags="+tags #proxies = {'http': 'http://127.0.0.1:8580'} proxies={} feedinput = urllib.urlopen(url, proxies=proxies).read() p1 = feedinput.find("[") p2 = feedinput.rfind("]") feedinput1 = feedinput[p1: p2+1] entries = json.loads(feedinput1) for entry in entries: title = entry["title"] url = entry["media"]['m'] link = entry["link"] pos1 = link.rfind("/") pos2 = link.rfind("/",0,pos1-1) photo_id = link[pos2+1:pos1] photo_id = photo_id.strip() sd = entry["date_taken"] if sd[-6] == '-': sd = sd[0:-6] format = "%Y-%m-%dT%H:%M:%S" d = time.strptime(sd, format) date_taken = datetime.fromtimestamp(mktime(d)) current_time = datetime.now() delta = current_time - date_taken if delta> timedelta(days=userinfo.flickr_max_days): logging.info("%s: time exceed "%photo_id) self.response.out.write("time exceed exist %s <br/>"%photo_id) continue logging.info("%s"% photo_id) self.response.out.write("%s<br/>"% photo_id) photo = FlickrRecord.gql('WHERE photo_id=:1', photo_id).get() #photo = None if photo: logging.info("photo exist") self.response.out.write("photo exist <br/>") continue e = FlickrRecord() e.photo_id = photo_id e.title = title e.url = url e.link = link e.date = date_taken list.append(e) return list