def _convert_feed(self, json, since): """Convert the json feed into Service Items limiting on since. """ items = [] # FIXME add filter on date! for entry in json: # Check we have a valid feed if entry != '404 Not Found': item = ServiceItem() created = datetime.strptime(entry['dt'], '%Y-%m-%dT%H:%M:%SZ') #'2010-11-23T22:03:29Z' if created.date() >= since: try: item.title = entry['d'] item.body = entry['n'] item.created = created item.link_back = entry['u'] item.notes = entry['n'] item.tags = entry['t'] item.service = self.service items.append(item) except: pass return items
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 _convert_photos_feed(self, photos, since): """Convert photo feed.""" items = [] for photo in photos['data']: if photo.has_key('created_time'): created = self._convert_time_stamp(photo['created_time']) if created.date() >= since: item = ServiceItem() item.created = created item.link_back = photo['link'] item.title = photo['name'] if photo.has_key('images'): try: item.body = photo['images'][3] except: pass item.url = photo['link'] item.tags = [] if photo.has_key('tags'): for tag in photo['tags']['data']: item.tags.append(tag['name']) item.comments = [] if photo.has_key('comments'): for comment in photo['comments']['data']: item.comments.append({'name' : comment['from']['name'], 'message' : comment['message'] }) 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