def internal_clipper_iframe(): if not (g.session_info.visitor_id or g.session_info.email): return render_template('clipper_iframe_not_logged_in.html') trip_plan_service = serviceimpls.TripPlanService(g.session_info) all_trip_plans = trip_plan_service.get(serviceimpls.TripPlanGetRequest()).trip_plans source_url = trip_plan_creator.canonicalize_url(request.values.get('url')) current_trip_plan = None for trip_plan in all_trip_plans: if trip_plan.source_url == source_url: current_trip_plan = trip_plan break if not current_trip_plan: admin_service = serviceimpls.AdminService(g.session_info) parse_request = serviceimpls.ParseTripPlanRequest(url=source_url, augment_entities=False) parse_response = admin_service.parsetripplan(parse_request) current_trip_plan = parse_response.trip_plan all_trip_plans.append(current_trip_plan) def comp(x, y): if x is current_trip_plan: return -1 if y is current_trip_plan: return 1 return x.compare(y) sorted_trip_plans = sorted(all_trip_plans, cmp=comp) return render_template('internal_clipper_iframe.html', all_trip_plans_json=serializable.to_json_str(sorted_trip_plans), all_datatype_values=values.ALL_VALUES)
def main(infile): db_user = user.User.get_by_email(GUIDE_USER) assert db_user session_info = data.SessionInfo(db_user=db_user) service = serviceimpls.AdminService(session_info) logfile = lf = open('bulk_guide_creator_%s.log' % \ datetime.datetime.now().strftime('%Y%m%d-%H-%M-%S'), 'w') all_trip_plans_for_user = data.load_all_trip_plans_for_creator(db_user.id) for line in infile: url = line.strip() if not trip_plan_creator.has_parser(url): logprint(lf, 'Unable to find parser: %s\n-----' % url) continue if SKIP_IF_GUIDE_EXISTS: canonical_url = trip_plan_creator.canonicalize_url(url) guide_exists = False for trip_plan in all_trip_plans_for_user: if trip_plan.source_url == canonical_url: logprint(lf, 'Trip plan already exists (%d): %s' % ( trip_plan.trip_plan_id, url)) guide_exists = True break if guide_exists: continue logprint(lf, 'Beginning parsing on %s' % url) req = serviceimpls.ParseTripPlanRequest(url=url) try: resp = service.parsetripplan(req) except Exception: logprint(lf, 'Error: %s\n%s\n-----' % (url, traceback.format_exc())) continue logprint(lf, 'Completed parsing %s (%d): "%s"' % ( url, resp.trip_plan.trip_plan_id, resp.trip_plan.name)) all_trip_plans_for_user.append(resp.trip_plan) logprint(lf, '-----') time.sleep(SLEEP_TIME_SECS) logfile.close()