예제 #1
0
 def scrape(self, user_data):
     """
     Scrape photos from google photos using the following API:
         https://developers.google.com/drive/v3/reference/
     """
     try:
         oauth = user_data.services['google']
     except KeyError:
         return False
     if 'denied' in oauth:
         return False
     credentials = client.OAuth2Credentials(
         access_token=oauth['access_token'],
         client_id=CONFIG.get('google_client_id'),
         client_secret=CONFIG.get('google_client_secret'),
         refresh_token=oauth.get('refresh_token', None),
         token_uri=client.GOOGLE_TOKEN_URI,
         token_expiry=oauth.get('expires_in', None),
         user_agent='QS-server-agent/1.0',
         id_token=oauth.get('id_token', None))
     http = credentials.authorize(httplib2.Http())
     gplus = build('drive', 'v3', http=http)
     photos = list(
         apiclient_paginate(gplus.files(),
                            'list', {
                                'spaces': 'photos',
                                'fields': 'files,kind,nextPageToken',
                            },
                            max_results=self.num_images_per_user))
     for photo in photos:
         faces = yield find_faces_url(photo['thumbnailLink'], upsample=2)
         photo['faces'] = faces
     return photos
예제 #2
0
 def scrape(self, user_data):
     """
     Scrape photos from google photos using the following API:
         https://developers.google.com/drive/v3/reference/
     """
     try:
         oauth = user_data.services['google']
     except KeyError:
         return False
     if 'denied' in oauth:
         return False
     credentials = client.OAuth2Credentials(
         access_token=oauth['access_token'],
         client_id=CONFIG.get('google_client_id'),
         client_secret=CONFIG.get('google_client_secret'),
         refresh_token=oauth.get('refresh_token', None),
         token_uri=client.GOOGLE_TOKEN_URI,
         token_expiry=oauth.get('expires_in', None),
         user_agent='QS-server-agent/1.0',
         id_token=oauth.get('id_token', None)
     )
     http = credentials.authorize(httplib2.Http())
     gplus = build('drive', 'v3', http=http)
     photos = list(apiclient_paginate(gplus.files(), 'list', {
         'spaces': 'photos',
         'fields': 'files,kind,nextPageToken',
     }, max_results=self.num_images_per_user))
     for photo in photos:
         faces = yield find_faces_url(photo['thumbnailLink'], upsample=2)
         photo['faces'] = faces
     return photos
예제 #3
0
 def parse_photos(self, graph, photos):
     for photo in photos:
         if 'tags' not in photo:
             continue
         photo['images'].sort(key=lambda x: x['height']*x['width'])
         image_url = photo['images'][-1]
         width, height = image_url['width'], image_url['height']
         people = [
             (
                 point(int(t['x']*width/100.0),
                       int(t['y']*height/100.0)),
                 t
             )
             for t in photo['tags']['data']
             if t.get('x') and t.get('y')
         ]
         faces = yield find_faces_url(image_url['source'], hash_face=True)
         # go through the faces _we_ found and interpolate those results
         # with the tags from the image
         for face in faces:
             face['tags'] = []
             for p, tag in people:
                 if face['rect'].contains(p):
                     face['tags'].append(tag)
         photo['faces'] = faces
     return photos
예제 #4
0
    def get_friends_profile(self, graph):
        friends_raw = yield facebook_paginate(
            graph.get_connections(
                'me',
                'feed',
                fields='from'
            ),
            max_results=None,
        )
        friends = {d['from']['id']: d['from']['name']
                   for d in friends_raw}
        pictures = []
        profile_pic = 'http://graph.facebook.com/{}/picture?type=large'
        for fid, fname in friends.items():
            photo = {
                'url': profile_pic.format(fid),
                'id': 'img-' + fid,
            }

            faces = yield find_faces_url(photo['url'], hash_face=True)
            # go through the faces _we_ found and interpolate those results
            # with the tags from the image
            for face in faces:
                face['tags'] = [{'name': fname, 'id': fid}]
            photo['faces'] = faces
            pictures.append(photo)
        return pictures
예제 #5
0
    def get_friends_profile(self, graph):
        friends_raw = yield facebook_paginate(graph.get_connections("me", "feed", fields="from"), max_results=None)
        friends = {d["from"]["id"]: d["from"]["name"] for d in friends_raw}
        pictures = []
        profile_pic = "http://graph.facebook.com/{}/picture?type=large"
        for fid, fname in friends.items():
            photo = {"url": profile_pic.format(fid), "id": "img-" + fid}

            faces = yield find_faces_url(photo["url"], hash_face=True)
            # go through the faces _we_ found and interpolate those results
            # with the tags from the image
            for face in faces:
                face["tags"] = [{"name": fname, "id": fid}]
            photo["faces"] = faces
            pictures.append(photo)
        return pictures
예제 #6
0
 def parse_photos(self, graph, photos):
     for photo in photos:
         if "tags" not in photo:
             continue
         photo["images"].sort(key=lambda x: x["height"] * x["width"])
         image_url = photo["images"][-1]
         width, height = image_url["width"], image_url["height"]
         people = [
             (point(int(t["x"] * width / 100.0), int(t["y"] * height / 100.0)), t)
             for t in photo["tags"]["data"]
             if t.get("x") and t.get("y")
         ]
         faces = yield find_faces_url(image_url["source"], hash_face=True)
         # go through the faces _we_ found and interpolate those results
         # with the tags from the image
         for face in faces:
             face["tags"] = []
             for p, tag in people:
                 if face["rect"].contains(p):
                     face["tags"].append(tag)
         photo["faces"] = faces
     return photos