예제 #1
0
def fb_upload(cfg, fn):
    print "Uploading %s to facebook" % fn
    graph = facebook.GraphAPI(settings.FB_APP_TOKEN)

    if len(cfg['photopops_fb_album_id']) == 0:
        print "no album"
        fb_res = graph.put_object(settings.FB_PHOTOPOPS_PAGE_ID,
                                  "albums",
                                  name=cfg['title'],
                                  message=cfg['title'])
        cfg['photopops_fb_album_id'] = fb_res['id']
        album_id = fb_res['id']
    else:
        album_id = cfg['photopops_fb_album_id']

    saveconfig(cfg)

    photo = Image.open("/opt/photopops/events/%s/proc/%s" %
                       (cfg['shortname'], fn))
    photo = photo.resize((800, 1200))
    photo_fn = "fb-%s" % fn

    mark = Image.open("/opt/photopops/assets/logo-angled-240x102.png")
    if mark.mode != 'RGBA':
        print "Converting %s/%s" % (EV_ORIG_DIR, fn)
        mark = mark.convert('RGBA')

    # Set opacity on watermark
    alpha = mark.split()[3]
    alpha = ImageEnhance.Brightness(alpha).enhance(0.7)
    mark.putalpha(alpha)

    # Create a new transparent layer the size of the original image
    layer = Image.new('RGBA', photo.size, (0, 0, 0, 0))
    layer.paste(
        mark,
        (photo.size[0] - mark.size[0] - 25, photo.size[1] - mark.size[1] - 25))

    # Add watermark layer to original image and save in processed directory
    proc = Image.composite(layer, photo, layer)
    proc.save("/opt/photopops/events/%s/proc/%s" %
              (cfg['shortname'], photo_fn),
              'JPEG',
              quality=70)

    fb_photo = open(
        "/opt/photopops/events/%s/proc/%s" % (cfg['shortname'], photo_fn),
        "rb")
    fb_res = graph.put_photo(fb_photo, album_id, photo_fn)
    fb_photo.close()

    del album_id
예제 #2
0
    def get_connection_values(self, response):
        if response:
            access_token = response['access_token']

            graph = facebook.GraphAPI(access_token)
            profile = graph.get_object("me")
            p_url = "http://facebook.com/profile.php?id=%s" % profile['id']
            i_url = "http://graph.facebook.com/%s/picture" % profile['id']
            return {
                "user_id": current_user.get_id(),
                "provider_id": self.provider_id,
                "provider_user_id": profile['id'],
                "access_token": access_token,
                "secret": None,
                "display_name": profile['username'],
                "profile_url": p_url,
                "image_url": i_url
            }

        return None
예제 #3
0
 def get_provider_user_id(self, response):
     if response != None:
         graph = facebook.GraphAPI(response['access_token'])
         profile = graph.get_object("me")
         return profile['id']
     return None
예제 #4
0
 def _create_api(self, connection):
     return facebook.GraphAPI(connection['access_token'])
예제 #5
0
def get_facebook_profile(token):
    graph = facebook.GraphAPI(token)
    return graph.get_object("me")