Skip to content

Commit a426f02

Browse files
committed
Add option to specified search engine to query
1 parent ef7de94 commit a426f02

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/cmd/gather/searchEngine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func init() {
3030
searchEngineCmd.Flags().StringVarP(&searchEngineOptions.Format, "format", "f", "", "Format (ex:{first}.{last}@domain.com, domain\\{f}{last}")
3131
searchEngineCmd.Flags().StringVarP(&searchEngineOptions.Company, "company", "c", "", "Company name")
3232
searchEngineCmd.Flags().BoolVarP(&searchEngineOptions.ExactMatch, "exactMatch", "e", false, "Exact match of the company's name")
33+
searchEngineCmd.Flags().StringVarP(&searchEngineOptions.SearchEngine, "searchEngine", "s", "", "Select on which search engine the query will be made, ex: bing,google (default: all)")
3334
searchEngineCmd.MarkFlagRequired("company")
3435
searchEngineCmd.MarkFlagRequired("format")
3536
}

src/searchEngine/gather.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ var REGEX_LINKEDIN = `<h[23](.*?")?>(?P<FirstName>.*?) (?P<LastName>.*?) [-–]
2020
// Gather will search a company name and returned the list of people in specified format
2121
func (options *Options) Gather() []string {
2222
var output []string
23+
var searchEngineToUse []string
2324
log = options.Log
2425
// Always insensitive case compare
2526
options.Company = strings.ToLower(options.Company)
26-
for searchEngine, formatUrl := range SEARCH_ENGINE {
2727
log.Target = searchEngine
2828
log.Verbose("Searching on " + searchEngine + " about " + options.Company)
2929
url := fmt.Sprintf(formatUrl, options.Company, 0)
@@ -38,6 +38,18 @@ func (options *Options) Gather() []string {
3838
log.Error("Too many requests")
3939
continue
4040
}
41+
if options.SearchEngine != "" {
42+
searchEngineToUse = strings.Split(options.SearchEngine, ",")
43+
} else {
44+
searchEngineToUse = utils.GetKeysMap(SEARCH_ENGINE)
45+
}
46+
// For specififed search engine
47+
for _, searchEngine := range searchEngineToUse {
48+
formatUrl := SEARCH_ENGINE[searchEngine]
49+
// Reset the variables values
50+
var startSearch = 0
51+
52+
// Compile the regex. May be different for each search engine
4153
reTitle := regexp.MustCompile(REGEX_TITLE)
4254
reData := regexp.MustCompile(REGEX_LINKEDIN)
4355
// Extract all links of the body

src/searchEngine/struct.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var log *logger.Logger
99

1010
// Options for searchengine module
1111
type Options struct {
12-
Format string
13-
ExactMatch bool
12+
Format string
13+
ExactMatch bool
14+
SearchEngine string
1415
utils.BaseOptions
1516
}

src/utils/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,13 @@ func GetBodyInWebsite(url string, proxy func(*http.Request) (*url.URL, error), h
126126
body, _ := ioutil.ReadAll(resp.Body)
127127
return string(body), resp.StatusCode, nil
128128
}
129+
130+
131+
// GetKeysMap return all the keys of the map. According to https://programmerah.com/how-to-get-all-the-keys-of-map-by-golang-1723/ this is the most efficient way to do it
132+
func GetKeysMap(m map[string]string) []string {
133+
keys := make([]string, 0, len(m))
134+
for k := range m {
135+
keys = append(keys, k)
136+
}
137+
return keys
138+
}

0 commit comments

Comments
 (0)