def get_items(user, since, model_instance): """Fetch and normalise the updates from the service.""" serv = model_instance or get_model_instance(user, __name__) access_token = AccessToken.objects.get(service=serv) flickr = flickrapi.FlickrAPI(access_token.api_token) photos = _get_service_items(user, model_instance, flickr, serv, access_token) items = [] if photos and photos['photos'].has_key('photo'): for photo in photos['photos']['photo']: # info about the pic pic = flickr.photos_getInfo(photo_id=photo['id'], format='json', nojsoncallback='1') pic_json = simplejson.loads(pic) item = ServiceItem() item.title = pic_json['photo']['title']['_content'] # use date from when the photo was uploaded to flickr NOT when it was taken item.created = datetime.fromtimestamp(float(pic_json['photo']['dates']['posted'])) #u'posted': u'1300054696' item.service = serv item.link_back = pic_json['photo']['urls']['url'][0]['_content'] item.tags = pic_json['photo']['tags']['tag'] item.favorite = pic_json['photo']['isfavorite'] item.url_thumb = "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg" % \ (pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret']) item.url_small = "http://farm%s.static.flickr.com/%s/%s_%s_m.jpg" % \ (pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret']) item.body = "<br/><img src='" + item.url_thumb +"'/>" # add location item.user = user items.append(item) return items
def get_items(self, since): """Fetch and normalise the updates from the service. """ # http://api.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=123&user_id=50685137%40N00&format=json&nojsoncallback=1&auth_token=123&api_sig=123 # http://www.flickr.com/services/api/explore/flickr.people.getPhotos user_id = self._get_username() if not user_id: return photos = self._get_oauth_v1('http://api.flickr.com/services/rest/?method=flickr.people.getPhotos&user_id=%s&format=json&nojsoncallback=1&min_upload_date=%s' % (user_id, since.strftime('%Y-%m-%d+%H:%M:%S'))) items = [] if photos and int(photos['photos']['total']) > 0: for photo in photos['photos']['photo']: # Info about the pic #pic = self.flickr.photos_getInfo(photo_id=photo['id'], format='json', nojsoncallback='1') pic_json = self._get_oauth_v1('http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&user_id=%s&format=json&nojsoncallback=1&photo_id=%s' % (user_id, photo['id'])) item = ServiceItem() item.title = pic_json['photo']['title']['_content'] item.body = pic_json['photo']['description']['_content'] # Use date from when the photo was uploaded to flickr NOT when it was taken item.created = datetime.fromtimestamp(float(pic_json['photo']['dates']['posted'])) #u'posted': u'1300054696' item.link_back = pic_json['photo']['urls']['url'][0]['_content'] item.tags = pic_json['photo']['tags']['tag'] item.favorite = pic_json['photo']['isfavorite'] item.url_thumb = "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.url_small = "http://farm%s.static.flickr.com/%s/%s_%s_m.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.body = '<br/><img src="%s" />' % (item.url_thumb,) item.service = self.service items.append(item) return items
def get_items(self, since): """Fetch and normalise the updates from the service. """ self.flickr = flickrapi.FlickrAPI(self.service.app.auth_settings['api_key']) photos = self._get_service_items(since) or {} items = [] if photos: for photo in photos: # Info about the pic pic = self.flickr.photos_getInfo(photo_id=photo['id'], format='json', nojsoncallback='1') pic_json = simplejson.loads(pic) item = ServiceItem() item.title = pic_json['photo']['title']['_content'] item.body = pic_json['photo']['description']['_content'] # Use date from when the photo was uploaded to flickr NOT when it was taken item.created = datetime.fromtimestamp(float(pic_json['photo']['dates']['posted'])) #u'posted': u'1300054696' item.link_back = pic_json['photo']['urls']['url'][0]['_content'] item.tags = pic_json['photo']['tags']['tag'] item.favorite = pic_json['photo']['isfavorite'] item.url_thumb = "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.url_small = "http://farm%s.static.flickr.com/%s/%s_%s_m.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.body = '<br/><img src="%s" />' % (item.url_thumb,) item.service = self.service items.append(item) return items
def get_stats_items(self, since): """Fetch and normalise the updates from the service and generate stats. """ self.flickr = flickrapi.FlickrAPI(self.service.app.auth_settings['api_key']) photos = self._get_service_items(since) items = [] if photos: for photo in photos: item = ServiceItem() # Info about the pic pic = self.flickr.photos_getInfo(photo_id=photo['id'], format='json', nojsoncallback='1') pic_json = simplejson.loads(pic) # Info about how the pic was taken exif = self.flickr.photos_getExif(photo_id=photo['id'], format='json', nojsoncallback ='1') exif_json = simplejson.loads(exif) item.camera_make, item.camera_model = self._extract_camera_type(exif_json) item.title = pic_json['photo']['title']['_content'] item.body = pic_json['photo']['description']['_content'] # Use date from when the photo was uploaded to flickr NOT when it was taken item.created = datetime.fromtimestamp(float(pic_json['photo']['dates']['posted'])) #u'posted': u'1300054696' item.link_back = pic_json['photo']['urls']['url'][0]['_content'] item.tags = pic_json['photo']['tags']['tag'] item.favorite = pic_json['photo']['isfavorite'] # Add views item.views = pic_json['photo']['views'] # Add tags item.tags = pic_json['photo']['tags']['tag'] item.number_of_comments = pic_json['photo']['comments']['_content'] item.url_thumb = "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.url_small = "http://farm%s.static.flickr.com/%s/%s_%s_m.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.body = '<br/><img src="%s" />' % (item.url_thumb,) # Add location item.location = {} if pic_json['photo'].has_key('location'): item.location['lat'] = pic_json['photo']['location']['latitude'] item.location['long'] = pic_json['photo']['location']['longitude'] item.service = self.service items.append(item) return items
def get_stats_items(self, since): """Fetch and normalise the updates from the service and generate stats. """ user_id = self._get_username() if not user_id: return photos = self._get_oauth_v1('http://api.flickr.com/services/rest/?method=flickr.people.getPhotos&user_id=%s&format=json&nojsoncallback=1&min_upload_date=%s' % (user_id, since.strftime('%Y-%m-%d+%H:%M:%S'))) items = [] if photos and int(photos['photos']['total']) > 0: for photo in photos['photos']['photo']: item = ServiceItem() # Info about the pic pic_json = self._get_oauth_v1('http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&user_id=%s&format=json&nojsoncallback=1&photo_id=%s' % (user_id, photo['id'])) # Info about how the pic was taken exif_json = self._get_oauth_v1('http://api.flickr.com/services/rest/?method=flickr.photos.getExif&user_id=%s&format=json&nojsoncallback=1&photo_id=%s' % (user_id, photo['id'])) item.camera_make, item.camera_model = self._extract_camera_type(exif_json) item.title = pic_json['photo']['title']['_content'] item.body = pic_json['photo']['description']['_content'] # Use date from when the photo was uploaded to flickr NOT when it was taken item.created = datetime.fromtimestamp(float(pic_json['photo']['dates']['posted'])) #u'posted': u'1300054696' item.link_back = pic_json['photo']['urls']['url'][0]['_content'] item.tags = pic_json['photo']['tags']['tag'] item.favorite = pic_json['photo']['isfavorite'] # Add views item.views = pic_json['photo']['views'] # Add tags item.tags = pic_json['photo']['tags']['tag'] item.number_of_comments = pic_json['photo']['comments']['_content'] item.url_thumb = "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.url_small = "http://farm%s.static.flickr.com/%s/%s_%s_m.jpg" % ( pic_json['photo']['farm'], pic_json['photo']['server'], pic_json['photo']['id'], pic_json['photo']['secret'] ) item.body = '<br/><img src="%s" />' % (item.url_thumb,) # Add location item.location = {} if pic_json['photo'].has_key('location'): item.location['lat'] = pic_json['photo']['location']['latitude'] item.location['long'] = pic_json['photo']['location']['longitude'] item.service = self.service items.append(item) return items