Exemplo n.º 1
0
def import_from_jlg_restaurant_csv(username, city, trip_plan_name, infile):
    reader = csv.reader(infile)
    trip_plan = data.TripPlan(data.generate_trip_plan_id(), trip_plan_name, creator=username)
    reader.next()  # Header row
    for row in reader:
        if not row:
            continue
        name = row[0]
        if not name:
            continue
        notes = row[1]
        verdict = row[3]
        description = '%s\n\n%s' % (notes, verdict)
        description = description.strip()
        yelp_response = yelp.search_by_term(name, city)
        if not yelp_response or not yelp_response.first_result():
            print 'No results for %s in %s' % (name, city)
            continue
        result = yelp_response.first_result()
        clip_result = clip_logic.scrape_and_build_entity(result['url'], trip_plan)
        if clip_result.entity:
            clip_result.entity.description = description
        print '%s clip status: %s' % (name, clip_result.status)
    data.save_trip_plan(trip_plan)
    return trip_plan
def main(cmd, input):
    if cmd in ('full', 'candidate'):
        url = input
        creator = TripPlanCreator(url)
        if cmd == 'full':
            trip_plan = creator.parse_full()
        elif cmd == 'candidate':
            trip_plan = creator.parse_candidate()
        else:
            return
        trip_plan.trip_plan_id = data.generate_trip_plan_id()
        data.save_trip_plan(trip_plan)
        print 'Successfully created trip plan %s with id %d' % (trip_plan.name, trip_plan.trip_plan_id)
        print trip_plan.to_json_str(pretty_print=True)
    elif cmd == 'augment':
        trip_plan_id = int(input)
        raw_trip_plan = data.load_trip_plan_by_id(trip_plan_id)
        trip_plan = augment_trip_plan(raw_trip_plan)
        data.save_trip_plan(trip_plan)
        print 'Successfully augmented trip plan %s with id %d' % (trip_plan.name, trip_plan.trip_plan_id)
        print trip_plan.to_json_str(pretty_print=True)