예제 #1
0
def index():
    if not 'oauth_token' in session:
        return redirect(url_for('login'))
    else:

        facebook_profile = facebook.get('/me')

        if facebook_profile.status == 200:  #200 means success
            facebook_profile = facebook_profile.data
        else:
            print "get facebook/me failed"

        notifications = facebook.get("me/notifications")

        if notifications.status == 200:  #200 means success
            notifications = notifications.data
        else:
            print "get facebook/me/notifications failed"

    print "Profile:%s" % facebook_profile
    print "Notifications:%s" % notifications

    return render_template('index.html',
                           facebook_profile=facebook_profile,
                           notifications=notifications)
예제 #2
0
def notifier():
    if not 'oauth_token' in session:
        return redirect(url_for('login'))
    notifications = facebook.get("me/notifications")
    
    if notifications.status == 200: #200 means success
        notifications =  notifications.data
    else:
        print "get facebook/me/notifications failed"

    return '%s' % notifications
예제 #3
0
def notifier():
    if not 'oauth_token' in session:
        return redirect(url_for('login'))
    notifications = facebook.get("me/notifications")

    if notifications.status == 200:  #200 means success
        notifications = notifications.data
    else:
        print "get facebook/me/notifications failed"

    return '%s' % notifications
예제 #4
0
def index():
    if not 'oauth_token' in session:
        return redirect(url_for('login'))
    else:

        facebook_profile = facebook.get('/me')
        

        # ex = User.objects(username = '******').first() #Also .all
        # print ex.username

        if facebook_profile.status == 200: #200 means success
            facebook_profile =  facebook_profile.data
            userID = facebook_profile['id']
            # firstNAME = facebook_profile['first_name']
            # lastNAME = facebook_profile['last_name']
            # userNAME = firstNAME + lastNAME
            for user in User.objects:
                if userID == user.user_id:
                    pass
                else:
                    user = User(user_id=userID, user_token=session.get('oauth_token')[0])
                    user.save()

        else:
            print "get facebook/me failed"

        notifications = facebook.get('me/notifications')

        if notifications.status == 200: #200 means success
            notifications =  notifications.data
        else:
            print "get facebook/me/notifications failed"

    print "Profile:%s" % facebook_profile
    print "Notifications:%s" % notifications

    return render_template('index.html', facebook_profile=facebook_profile, notifications=notifications)
예제 #5
0
def index():
    if not 'oauth_token' in session:
        return redirect(url_for('login'))
    else:

        facebook_profile = facebook.get('/me')

        if facebook_profile.status == 200: #200 means success
            facebook_profile =  facebook_profile.data
        else:
            print "get facebook/me failed"


        notifications = facebook.get("me/notifications")
        
        if notifications.status == 200: #200 means success
            notifications =  notifications.data
        else:
            print "get facebook/me/notifications failed"

    print "Profile:%s" % facebook_profile
    print "Notifications:%s" % notifications

    return render_template('index.html', facebook_profile=facebook_profile, notifications=notifications)
예제 #6
0
def notifier():
    #if not 'oauth_token' in session:
        #return redirect(url_for('login'))

    compliments_list = ["Baby, somebody better call God, cuz he's missing an angel!", 
                "Are you a tamale? Cause you're hot.", 
                "Apart from being sexy, what do you do for a living?",
                "Did it hurt? when you fell from heaven.",
                "Damn, if being sexy was a crime, you'd be guilty as charged!",
                "Baby, if you were words on a page, you'd be what they call fine print.",
                "Baby, you must be a broom, cause you just swept me off my feet.",
                "Did the sun come out or did you just smile at me?",
                "Is your sin pi/2? Becuase you're the one."]

    #Getting the access token to send notifications
    res = requests.get("https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=client_credentials" % (app.config['FACEBOOK_APP_ID'], app.config['FACEBOOK_APP_SECRET']))
    app_access_token = res.content.split('=')[1]
    param_string = urllib.urlencode({"access_token":app_access_token, "template":random.choice(compliments_list)}, True) #these have to be encoded in the url, urllib does this for us :-)
    
    for user in User.objects:
        userId = user.user_id


        #res = requests.post("https://graph.facebook.com/%s/notifications?%s" % (userId, param_string))
        #print res.content

        notifications = facebook.get("me/notifications")
            
        if notifications.status == 200: #200 means success
            notifications =  notifications.data
            #if you don't have notifications, run the notifier
            if notifications['data'] == []:
                res = requests.post("https://graph.facebook.com/%s/notifications?%s" % (userId, param_string))
        else:
            print "get facebook/me/notifications failed"


    #res = requests.post("https://graph.facebook.com/%s/notifications?%s" % (user_id, param_string))
    #print res.content

    return "HAVE MY BABIES!"