def get_nodes_text(nodes): text = '' for j in range(len(nodes)): if text != '': text += ', ' text += utils.remove_html_tags(utils.decode_unicode_references(str(nodes[j].renderContents()))) return text
def get_walking_route(start_location, end_location): params = { 'origin': start_location.to_url_param(), 'destination': end_location.to_url_param(), 'sensor' : 'false', 'mode': 'walking' } url = 'http://maps.google.com/maps/api/directions/json?' + urllib.urlencode(params) result = urlfetch.fetch(url) if result.status_code == 200: route = json.loads(result.content) if route['status'] == 'OVER_QUERY_LIMIT': logging.warn('OVER_QUERY_LIMIT while fetching walking directions') return None # Google refuses to work instructions = [] duration = 0 distance = 0 for leg in route['routes'][0]['legs']: for leg_step in leg['steps']: instructions.append(clean_walk_direction(utils.remove_html_tags(leg_step['html_instructions']))) duration += int(leg_step['duration']['value']) distance += int(leg_step['distance']['value']) step = RouteStep() step.direction = ', '.join(instructions).replace('M10','') step.duration = duration / 60 step.addinfo = utils.duration_to_string(step.duration) + ', ' + utils.distance_to_string(distance) step.transport = None # walk step.start_location = start_location step.end_location = end_location step.has_map = True return Route([step])
def get_walking_step(start_location, end_location, end_name = None): step = None direct_distance = estimate_distance(start_location, end_location) if direct_distance > 150: language = utils.get_language() params = { 'origin': start_location.to_url_param(), 'destination': end_location.to_url_param(), 'sensor' : 'false', 'mode': 'walking', 'language' : language } url = 'http://maps.google.com/maps/api/directions/json?' + urllib.urlencode(params) result = urlfetch.fetch(url) if result.status_code == 200: route = json.loads(result.content) if route['status'] == 'OVER_QUERY_LIMIT': logging.warn('OVER_QUERY_LIMIT while fetching walking directions') elif route['status'] == 'ZERO_RESULTS': # no route found pass else: instructions = [] duration = 0 distance = 0 for leg in route['routes'][0]['legs']: for leg_step in leg['steps']: instructions.append(clean_walk_direction(utils.remove_html_tags(leg_step['html_instructions']))) duration += int(leg_step['duration']['value']) distance += int(leg_step['distance']['value']) step = common.RouteStep() step.direction = ', '.join(instructions) step.duration = int(duration / 60) step.distance = distance else: logging.warn('Walking route failed: ' + str(result.status_code)) if step == None: #google not needed or failed step = common.RouteStep() step.distance = estimate_distance(start_location, end_location) * 1.4 step.duration = int(step.distance / 80 + 0.5) if end_name != None: walk_text = _('Walk to') + ' ' + end_name if step.direction != None: step.direction = walk_text + ': ' + step.direction else: step.direction = walk_text elif step.direction == None: step.direction = _('Walk') + ' ' + utils.distance_to_string(step.distance) step.transport = None # walk step.start_location = start_location step.end_location = end_location step.has_map = True return step
def get_node_text(node): if node != None: return utils.remove_html_tags(utils.decode_unicode_references(str(node.renderContents()).strip())) return ''