コード例 #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 band_to_city(band, city):
    """
    Create an 'is_from' relationship between a band and city.

    :param band: the username of the band.
    :param city: the name of the city.
    """
    band = db.get_node('band', 'username', band)
    city = db.get_node('city', 'name', city)
    if not db.check_relationship(band, 'is_from'):
        print 'Connecting %s to %s...' % (band['name'], city['name'])
        db.add_relationship(band, 'is_from', city)
コード例 #3
0
def event_to_band(event, band):
    """
    create a 'featuring' relationship between an event and a band.

    :param event: the event dictionary.
    :param band: the band dictionary.
    """
    e = db.get_node('event', 'id', event['id'])
    b = db.get_node('band', 'username', band['username'])
    if not db.check_relationship(e, 'featuring', b):
        print "Connecting event to %s..." % unicodedata.normalize(
            'NFKD', b['name'])
        db.add_relationship(e, 'featuring', b)
コード例 #4
0
def event_to_venue(event, venue):
    """
    Create an 'at' relationship between an event and a venue.

    :param event: the event dictionary.
    :param venue: the venue dictionary.
    """
    e = db.get_node('event', 'id', event['id'])
    v = db.get_node('venue', 'id', venue['id'])
    if not db.check_relationship(e, 'at'):
        print "Connecting event to %s..." % unicodedata.normalize(
            'NFKD', v['name'])
        db.add_relationship(e, 'at', v)
コード例 #5
0
def city_to_state(city, state):
    """
    Create an 'is_in' relationship between a city and a state.

    :param city: the name of the city.
    :param state:  the name or abbreviation of the state.
    """
    city = db.get_node('city', 'name', city)
    if len(state) == 2:
        state = db.get_node('state', 'abbr', state)
    else:
        state = db.get_node('state', 'name', state)
    if not db.check_relationship(city, 'is_in'):
        print 'Connecting %s to %s...' % (city['name'], state['name'])
        db.add_relationship(city, 'is_in', state)
コード例 #6
0
def venue_to_city(venue, city):
    """
    Create an 'is_in' relationship between a venue and a city.

    :param venue: the venue dictionary.
    :param city:  the city dictionary.
    """
    if 'username' in venue.keys():
        venue = db.get_node('venue', 'username', venue['username'])
    else:
        venue = db.get_node('venue', 'id', venue['id'])
    city = db.get_node('city', 'name', city['name'])
    if not db.check_relationship(venue, 'is_in'):
        print 'Connecting %s to %s...' % (unicodedata.normalize(
            'NFKD', venue['name']), city['name'])
        db.add_relationship(venue, 'is_in', city)