Exemplo n.º 1
0
def main():
    try:
        print "Welcome to creative recipe v1.0"
        while (True):
            query = raw_input("Enter a search query(q/Q to quit): ")
            if query == 'q' or query == 'Q':
                print "Bye! Have fun!"
                break
            print "Getting recipe from AllRecipe.com"
            results = scrapeSearch(query)
            print "Searching Done!"
            if not results:
                print "I don't think it is some kind of food, do you?"
            else:
                print "Search results:"
		select = selectRecipe(results);
                print "Processing..."
                recipe = scrapeRecipe(select.replace(" ","-"))
                recipe.my_print()
                print "Done! "

    except KeyboardInterrupt:
        print
Exemplo n.º 2
0
import scrape
import sys

authorsFile = open(sys.argv[1], 'r')
keywordsFile = open(sys.argv[2], 'r')
lastDate = sys.argv[3]

authors = authorsFile.readlines()
keywords = keywordsFile.readlines()

for author in authors:
    for keyword in keywords:
        author = author.strip()
        keyword = keyword.strip()
        print author, keyword
        scrape.scrapeSearch(author, keyword, lastDate)

keywordsFile.close()
authorsFile.close()
Exemplo n.º 3
0
def main():
    try:
        stdout.write("Reticulating splines...\n")
        loadNltk()
        while (True):
            stdout.write("Enter a search query: ")
            query = trim(stdin.readline())
            if not query:
                stdout.write("Exiting.\n")
                break
            stdout.write("Scraping...")
            stdout.flush()
            results = scrapeSearch(query)
            stdout.write(" Done!\n")
            if not results:
                stdout.write("You can't eat that!\n")
            else:
                stdout.write("Results:\n")
                stdout.write("Choose a recipe:\n")
                choice = getChoice([x[0] for x in results[0:10]])
                stdout.write("Scraping...")
                stdout.flush()
                recipe = scrapeRecipe(results[choice][1])
                stdout.write(" Done!\n\n")
                stdout.write(recipe.prettify())
                stdout.write("\n")
                stdout.write("Now what?\n")
                next_choices = ['search again', 'substitution', 'culture swap']
                has_culture = bool(recipe.ethnicities.keys())
                if has_culture:
                    choice = getChoice(next_choices)
                else:
                    next_choices[-1] = "culturize!"
                    choice = getChoice(next_choices)
                if choice == 0:
                    continue
                if choice == 1:
                    ingredients = sorted(recipe.ingredients.keys())
                    stdout.write("Take what out?\n")
                    choice = getChoice(ingredients)
                    to_remove = ingredients[choice]
                    try:
                        found = fuzzyfind(to_remove, nouns.keys())
                        category = nouns[found][0]
                    except KeyError:
                        category = 'misc'
                    candidates = [x for x in nouns.keys() if
                            fuzzyfind(to_remove, [x]) is None]
                    if category != 'misc':
                        candidates = [x for x in candidates if nouns[x][0] ==
                                category]
                    shuffle(candidates)
                    stdout.write("Put what in?\n")
                    choice = getChoice(candidates[0:6])
                    old_tuple = recipe.ingredients[to_remove]
                    to_add = (candidates[choice], old_tuple[0], old_tuple[1],
                            old_tuple[2])
                    recipe.changeIngredient(to_remove, to_add)
                    stdout.write(
                            "\nYour new recipe, substituting %s for %s:\n" % \
                            (to_add[0], to_remove))
                    stdout.write(recipe.prettify())
                    continue
                if choice == 2:
                    stdout.write("What spin you wanna give this?\n")
                    prefixes = ['vaguely', 'somewhat', 'potentially']
                    shuffle(prefixes)
                    pref = prefixes[0]
                    suffixes = ['ified', 'ated', '-style', 'ized']
                    shuffle(suffixes)
                    suff = suffixes[0]
                    ethnicity_list = [e for e in sorted(list(ethnicity_set)) if
                            e not in recipe.ethnicities]
                    choice = getChoice(ethnicity_list)
                    new_ethn = ethnicity_list[choice]
                    recipe.changeEthnicity(new_ethn)
                    stdout.write("Your new recipe, %s %s%s!\n" % (pref,
                        new_ethn, suff))
                    stdout.write(recipe.prettify())
                    continue
            stdout.write("\n")
    except KeyboardInterrupt:
        stdout.write("\n")