def find_routes_given_ingredients(user_location, ingredients): """ Finds the best driving routes for the user to purchase all the needed ingredients. :param user_location: the user's starting location - Location :param ingredients: a comma-separated list of the ingredients the user needs - string :return a list of routes, sorted best to worst """ Geolocation.load_lat_long_for_location(user_location) planner = TripPlanner(user_location) needed_items = ingredients.split(',') needed_items = [item.strip() for item in needed_items] print('Planning route from {} to get {}'.format(user_location, ', '.join(needed_items))) stores = get_stores_near_me(user_location, 20, 10) plans = planner.find_routes(needed_items, stores, 20, False) return plans
food = "&ItemName=" + food return base_url + SUPERMARKET_API_KEY + store + food if __name__ == '__main__': from flask import Flask, g from main import get_stores_near_me from models import Location from geolocation import Geolocation from planning import TripPlanner app = Flask(__name__) with app.app_context(): needed_items = ['apples', 'cashews', 'butternut squash'] try: user_loc = Location('1000 Olin Way', 'Needham', 'MA', 2492) Geolocation.load_lat_long_for_location(user_loc) stores = get_stores_near_me(user_loc, 10, 20) # sif = StoreItemFetcher(False) # sif.check_stores_for_ingredients(needed_items, stores) planner = TripPlanner(user_loc) plans = planner.find_routes(needed_items, stores, 20, False) for plan in plans: print(plan) finally: db = getattr(g, '_database', None) if db: db.close()