コード例 #1
0
def band(*args):
    print "Adding band '%s'..." % args[0]
    try:
        r = facebook.get(args[0], fields=config.app_fields_band)
        l, c, s = r.pop('location', None), None, None

        if l is not None:
            c = dict(name=l['city'])
            s = dict(abbr=l['state'])
        elif 'hometown' in r:
            c, s = PushPin.locate(r['hometown'])

        while c is None or s is None:
            l = raw_input(
                'Location for %s could not be determined. Please provide: ' %
                r['name'])
            c, s = PushPin.locate(l)
            if c is None or s is None: print "Invalid location"

        db.add_node('band', **r)
        if c is not None and s is not None:
            if not db.check_node('city', 'name', c['name']):
                city(c)
            if not db.check_relationship(
                    db.get_node('city', 'name', c['name']), 'is_in',
                    db.get_node('state', 'abbr', s['abbr'])):
                connect.city_to_state(c['name'], s['abbr'])
            connect.band_to_city(r['username'], c['name'])
    except error.types as e:
        error.handle(e, args[0])
    else:
        print "%s successfully added to database." % r['name']
コード例 #2
0
def event(event):
    """
    Add an event to the Neo4J database.

    :param event: the id of the event being added to the database
    :return: the event node returned from the database
    """
    print "Adding event '%s' to database..." % event['name']

    e = fb.get(event['id'], fields=config.app_fields_events)

    # Strip place property:
    if 'place' in e.keys():
        del e['place']

    dr = db.get_node('event', 'id', e['id'])

    db.add_node('event', 'id', **e)

    if dr is None:
        print "Event '%s' successfully added to database." % e['name']
    else:
        print "Event '%s' already exists. Existing record updated." % e['name']

    dr = db.get_node('event', 'id', e['id'])

    return dr
コード例 #3
0
def band(username):
    """
    Add a band to the Neo4J database.

    :param username: the username for the band being added to the database
    :return b: the band node returned from the database
    :return l: the band's location object from the facebook node, if it exists
    """
    username = username.lower()

    print "Adding band '%s'..." % username

    r = fb.get(username, fields=config.app_fields_band)
    l = r.pop('location', None)

    dr = db.get_node('band', 'username', username)

    r['username'] = r['username'].lower()
    db.add_node('band', 'username', **r)

    if dr is None:
        print "%s successfully added to database." % r['name']
    else:
        print "%s already exists. Existing record updated." % r['name']

    dr = db.get_node('band', 'username', username)

    return dr, l
コード例 #4
0
ファイル: views.py プロジェクト: campaigncollege/dd-css
def number_of_shares():
    if g.user is not None:
        fform = FollowersForm()
	if fform.validate_on_submit():
		url=fform.url_name.data
		q='?ids='+url
		resp = facebook.get(q)
		return render_template('fb/result_shares.html', resp=resp, url=url )
    	return render_template('fb/number_of_shares.html', fform = fform)
コード例 #5
0
def venue(*args):
    print "Adding venue '%s'..." % args[0]
    try:
        r = facebook.get(args[0], **{'fields': config.app_fields_venue})
        r, c, s = parse.location(r)
        db.add_node('venue', **r)
        if c is not None and s is not None:
            if not db.check_node('city', 'name', c):
                city(c)
                connect.city_to_state(c, s)
            connect.venue_to_city(r['username'], c)
    except error.types as e:
        error.handle(e, args[0])
    else:
        print "%s successfully added to database." % r['name']
コード例 #6
0
def venue(username=None, id=None):
    """
    Add a venue to the Neo4J database.

    :param username: the username/handle for the venue being added to the database
    :param id: the id for the venue being added to the database
    :return v: the venue node returned from the database
    :return l: the venue's location object from the facebook node
    """
    if username is not None:
        username = username.lower()
        search_value = username
        search_by = 'username'
    else:
        search_value = id
        search_by = 'id'

    print "Adding venue with %s '%s'..." % (search_by, search_value)

    r = fb.get(search_value, fields=config.app_fields_venue)
    l = r.pop('location', None)

    if l is not None:
        for key in l.keys():
            r[key] = l[key]

    dr = db.get_node('venue', search_by, search_value)

    if 'username' in r.keys():
        r['username'] = r['username'].lower()

    db.add_node('venue', 'id', **r)

    if dr is None:
        print "%s successfully added to database." % r['name']
    else:
        print "%s already exists. Existing record updated." % r['name']

    dr = db.get_node('venue', search_by, search_value)

    return dr, l
コード例 #7
0
ファイル: app.py プロジェクト: SwagCity/DYA
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['oauth_token'] = (resp['access_token'], '')
    session['token'] = resp['access_token']
    me = facebook.get('/me')
    session['name'] = me.data['name']
    fburl = "https://graph.facebook.com/v2.2/me?access_token=" + urllib.quote_plus(str((session["token"])))
    req = urllib2.urlopen(fburl)
    result = req.read()
    d = json.loads(result)
    # a = open('sample.json').read()
    # d = json.loads(a)
    session['id'] = d['id']
    if not db.idexists(session['id']):
        db.adduser(session['name'],session['id'],me.data['email'])
        return redirect(url_for('home'))
    return redirect(url_for('index'))
コード例 #8
0
ファイル: app.py プロジェクト: justinstrauss/finalproj
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'], request.args['error_description'])
    session['oauth_token'] = (resp['access_token'], '')
    session['token'] = resp['access_token']
    me = facebook.get('/me')
    session['name'] = me.data['name']
    fburl = "https://graph.facebook.com/v2.2/me?access_token=" + urllib.quote_plus(
        str((session["token"])))
    req = urllib2.urlopen(fburl)
    result = req.read()
    d = json.loads(result)
    # a = open('sample.json').read()
    # d = json.loads(a)
    session['id'] = d['id']
    if not database.user_exists(session['id']):
        database.add_user(session['name'], session['id'])
        flash("Since you are a new user, please update your food preferences.")
        return redirect(url_for('account'))
    return redirect(url_for('index'))
コード例 #9
0
import webbrowser, facebook
from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import facebook_compliance_fix

# Credentials you get from registering a new application
client_id = '1387733244617941'
client_secret = '0aebb282152cbca66116bd5707d8b0c5'

# OAuth endpoints given in the Facebook API documentation
authorization_base_url = 'https://www.facebook.com/dialog/oauth'
token_url = 'https://graph.facebook.com/oauth/access_token'
redirect_uri = 'http://www.myserver.com/coliw'  # Should match Site URL

facebook = OAuth2Session(client_id, redirect_uri=redirect_uri)
facebook = facebook_compliance_fix(facebook)

# Redirect user to Facebook for authorization
authorization_url, state = facebook.authorization_url(authorization_base_url)
webbrowser.open_new_tab(authorization_url)

print(state)
# Get the authorization verifier code from the callback url
redirect_response = 'https://www.myserver.com/coliw'
#
# # Fetch the access token
#facebook.fetch_token(token_url, client_secret=client_secret,
#                   authorization_response=redirect_response)

# Fetch a protected resource, i.e. user profile
r = facebook.get('https://graph.facebook.com/me?')
print(r.content)