-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
131 lines (117 loc) · 3.98 KB
/
main.go
File metadata and controls
131 lines (117 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
wordwrap "github.com/mitchellh/go-wordwrap"
meanrecipe "github.com/schollz/meanrecipe/v3/src"
"gopkg.in/AlecAivazis/survey.v1"
)
func main() {
fmt.Print(`
___ ___ ___ ____ ____ ____ ___ __ ____ ____ ___
| | | / _] / || \ | \ / _] / ]| || \ / _]
| _ _ | / [_ | o || _ | | D ) / [_ / / | | | o ) [_
| \_/ || _]| || | | | / | _]/ / | | | _/ _]
| | || [_ | _ || | | | \ | [_/ \_ | | | | | [_
| | || || | || | | | . \| \ | | | | | | |
|___|___||_____||__|__||__|__| |__|\_||_____|\____||____||__| |_____|`)
fmt.Print(`
_ _
_/0\/ \_
.-. .-` + "`" + ` \_/\0/ '-.
/:::\ / ,_________, \
/\:::/ \ '. (:::/ ` + "`" + `'-;
\ ` + "`" + `-'` + "`" + `\ '._ ` + "`" + `"'"'\__ \
` + "`" + `'-. \ ` + "`" + `)-=-=( ` + "`" + `, |
\ ` + "`" + `-"` + "`" + ` ` + "`" + `"-` + "`" + ` /
`)
var err error
var recipe, include string
var clusters int
var debug bool
flag.StringVar(&recipe, "recipe", "", "recipe to average (e.g. 'chocolate chip cookies')")
flag.StringVar(&include, "include", "", "ingredients to include")
flag.BoolVar(&debug, "debug", false, "set debug")
flag.IntVar(&clusters, "clusters", 30, "number of clusters to generate")
flag.Parse()
if len(recipe) == 0 {
// the questions to ask
var qs = []*survey.Question{
{
Name: "recipe",
Prompt: &survey.Input{Message: "What recipe (e.g. chocolate chip cookies)?"},
Validate: survey.Required,
Transform: survey.Title,
},
} // the answers will be written to this struct
answers := struct {
Recipe string // survey will match the question and field names
}{}
// perform the questions
err = survey.Ask(qs, &answers)
if err != nil {
fmt.Println(err.Error())
return
}
recipe = strings.ToLower(strings.TrimSpace(answers.Recipe))
}
if debug {
meanrecipe.SetLogLevel("debug")
} else {
meanrecipe.SetLogLevel("info")
}
ingredientsToInclude := []string{}
if len(include) > 0 {
for _, word := range strings.Split(include, ",") {
ingredientsToInclude = append(ingredientsToInclude, strings.ToLower(strings.TrimSpace(word)))
}
}
meanRecipes, err := meanrecipe.Run(recipe, clusters, ingredientsToInclude, true)
if err != nil {
fmt.Println("ERROR", err.Error())
}
fmt.Println(`
____ ___ _____ __ __ _ ______ _____
| \ / _]/ ___/| | || | | |/ ___/
| D ) / [_( \_ | | || | | ( \_
| / | _]\__ || | || |___|_| |_|\__ |
| \ | [_ / \ || : || | | | / \ |
| . \| |\ || || | | | \ |
|__|\_||_____| \___| \__,_||_____| |__| \___|
`)
for _, r := range meanRecipes {
fmt.Println("\n->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->\n\n")
fmt.Println(r.Title)
if len(r.HasRareIngredients) > 0 || len(r.MissingCommonIngredients) > 0 {
fmt.Println("Variation: ")
}
for _, ing := range r.HasRareIngredients {
fmt.Printf(" +%s", ing)
}
for _, ing := range r.MissingCommonIngredients {
fmt.Printf(" -%s", ing)
}
fmt.Println("\n\nIngredients:")
fmt.Println(r.IngredientText())
fmt.Println("Directions:")
for i, direction := range r.Directions {
fmt.Printf("%d. %s\n\n", i+1, wordwrap.WrapString(direction, 65))
}
urls := strings.Split(r.URL, ",")
if len(urls) > 10 {
urls = urls[:10]
}
fmt.Println(strings.Join(urls, "\n"))
}
fmt.Println("->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->")
common, rare := meanrecipe.GetIngredientFrequencies(meanRecipes)
fmt.Printf("Common ingredients: %s\n", strings.Join(common, ", "))
fmt.Printf("Rare ingredients: %s\n", strings.Join(rare, ", "))
// wait before exit
fmt.Println("\nPress any key to exit...")
buf := bufio.NewReader(os.Stdin)
buf.ReadBytes('\n')
}