ulvis.paste.net

restaurant in city
  1. import lat_long_to_dist
  2.  
  3. def parse_line(p_line):
  4.     line_parse = line.split('|', 6)
  5.     p_line = []
  6.     p_line.append(line_parse[0])
  7.     p_line.append(float(line_parse[1]))
  8.     p_line.append(float(line_parse[2]))
  9.     p_line.append(line_parse[5])
  10.     review_parse = line_parse[6].split('|')
  11.     p_line.append(review_parse)
  12.     sum = 0
  13.     for item in review_parse:
  14.         sum += int(item)
  15.     average = float(float(sum) / float(len(review_parse)))
  16.     p_line.append(average)  
  17.    
  18.  
  19. ###################################################################
  20. #
  21. #  Get the data that the program will work with.  Observe that the
  22. #  code immediately prints the input.  This helps the results look
  23. #  better when your program is submitted to and runs on the server.
  24. #
  25. ###################################################################
  26.  
  27.  
  28. # Get the current latitude and longitude.
  29. current_lat = float(raw_input("Enter current latitude ==> "))
  30. print current_lat
  31. current_long = float(raw_input("Enter current longitude ==> "))
  32. print current_long
  33.  
  34. # Get the maximum distance to consider
  35. max_dist = float(raw_input("Enter maximum distance (-1 for none) ==> "))
  36. has_max_dist = max_dist >= 0
  37. print max_dist
  38.  
  39. # Get the name of the city
  40. desired_city = raw_input("Enter the city restriction (blank for none) ==>")
  41. desired_city = desired_city.strip()       # eliminate leading and trailing blanks in the input
  42. has_desired_city = len(desired_city) > 0
  43. print desired_city
  44.  
  45. file = open('lab5businesses.txt','r')
  46.  
  47. print "Restaurants meeting your criteria:"
  48.  
  49. for line in file:
  50.     p_line = parse_line(line)
  51.     d = lat_long_to_dist.distance_from_lat_long( current_lat, current_long, p_line[1], p_line[2] )
  52.     dist_ok = not has_max_dist or d < max_dist
  53.     city_ok = not has_desired_city or restaurant_in_city( p_line, desired_city)
  54.    
  55.     if dist_ok and city_ok:
  56.         print_restaurant(p_line, d)
Parsed in 0.014 seconds