Skip to content

Commit 2401c16

Browse files
committed
Show more information (title name, location)
Add option to not convert to email Add debug
1 parent 42bbd18 commit 2401c16

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

src/cmd/gather/linkedin.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gather
33
import (
44
"GoMapEnum/src/linkedin"
55
"GoMapEnum/src/logger"
6+
"errors"
67

78
"github.com/spf13/cobra"
89
)
@@ -16,6 +17,12 @@ var linkedinCmd = &cobra.Command{
1617
Long: `Firstly, it will search for company based on the provided name and then list all the people working at these companies and print them in the specified format.
1718
The session cookie is needed to use the Linkedin features.`,
1819
Example: `go run main.go gather linkedin -c contoso -f "{f}{last}@contonso.com" -e -s AQEDA...`,
20+
PreRunE: func(cmd *cobra.Command, args []string) error {
21+
if linkedinOptions.Format == "" && linkedinOptions.Email {
22+
return errors.New("format flag is requre when email should be guess")
23+
}
24+
return nil
25+
},
1926
Run: func(cmdCli *cobra.Command, args []string) {
2027
log := logger.New("Gather", "linkedin", "Linkedin")
2128
log.SetLevel(level)
@@ -30,9 +37,9 @@ func init() {
3037

3138
linkedinCmd.Flags().StringVarP(&linkedinOptions.Format, "format", "f", "", "Format (ex:{first}.{last}@domain.com, domain\\{f}{last}")
3239
linkedinCmd.Flags().StringVarP(&linkedinOptions.Company, "company", "c", "", "Company name")
40+
linkedinCmd.Flags().BoolVar(&linkedinOptions.Email, "email", true, "Guess the email according to the format. If false print the first name and last name")
3341
linkedinCmd.Flags().BoolVarP(&linkedinOptions.ExactMatch, "exactMatch", "e", false, "Exact match of the company's name")
3442
linkedinCmd.Flags().StringVarP(&linkedinOptions.Cookie, "cookie", "s", "", "Session cookie named li_at")
3543
linkedinCmd.MarkFlagRequired("company")
3644
linkedinCmd.MarkFlagRequired("cookie")
37-
linkedinCmd.MarkFlagRequired("format")
3845
}

src/linkedin/gather.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func (options *Options) Gather() []string {
1919
options.Company = strings.ToLower(options.Company)
2020
// Get all the companies from the option
2121
companies := options.getCompany()
22+
log.Debug("Found " + strconv.Itoa(len(companies.Elements)) + " companies matching " + options.Company)
2223
for _, company := range companies.Elements {
2324
// Extract the company name from the struct
2425
companyLinkedinName := strings.ToLower(company.EntityLockupView.Title.Text)
@@ -29,6 +30,7 @@ func (options *Options) Gather() []string {
2930
companyID, _ := strconv.Atoi(strings.Split(company.EntityLockupView.TrackingUrn, ":")[3])
3031
// Get the people of the company, starting from 0
3132
output = options.getPeople(companyID, 0)
33+
log.Debug("Found " + strconv.Itoa(len(output)) + " peoples for " + options.Company)
3234
}
3335
}
3436

src/linkedin/struct.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var log *logger.Logger
1010
// Options for o365 module
1111
type Options struct {
1212
Format string
13+
Email bool
1314
ExactMatch bool
1415
Cookie string
1516
utils.BaseOptions

src/linkedin/utils.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func (options *Options) getCompany() linkedinListCompany {
3131
return companies
3232
}
3333
json.Unmarshal([]byte(body), &companies)
34-
log.Debug("Found " + strconv.Itoa(len(companies.Elements)) + " companies matching " + options.Company)
3534
return companies
3635
}
3736

@@ -64,15 +63,16 @@ func (options *Options) getPeople(companyID, start int) []string {
6463
}
6564

6665
numberPeople = len(element.Results)
66+
log.Debug("Found " + strconv.Itoa(numberPeople) + " from " + strconv.Itoa(start) + " for " + options.Company)
6767
for _, people := range element.Results {
6868
// if it is an anonymous user, skip it
6969
if people.Title.Text == "LinkedIn Member" {
7070
continue
7171
}
7272
// Parse the name to output in the specified format
7373
name := strings.Split(people.Title.Text, " ")
74-
// If the name is composed of more than 2 words, we skip it
75-
if len(name) == 2 {
74+
// If the name is composed of more than 2 words or the email should not be guessed, we skip it
75+
if len(name) == 2 && options.Email {
7676
var email string
7777
email = options.Format
7878
log.Verbose(name[0] + " - " + name[1])
@@ -81,9 +81,15 @@ func (options *Options) getPeople(companyID, start int) []string {
8181
email = strings.ReplaceAll(email, "{last}", name[1])
8282
email = strings.ReplaceAll(email, "{l}", name[1][0:1])
8383
email = strings.ToLower(email)
84-
log.Success(email + " - " + people.PrimarySubtitle.Text + "-" + people.SecondarySubtitle.Text)
84+
log.Success(email + " - " + people.PrimarySubtitle.Text + " - " + people.SecondarySubtitle.Text)
8585
output = append(output, email)
8686
}
87+
if !options.Email {
88+
result := people.Title.Text + " - " + people.PrimarySubtitle.Text + " - " + people.SecondarySubtitle.Text
89+
log.Success(result)
90+
output = append(output, result)
91+
92+
}
8793

8894
}
8995
}

0 commit comments

Comments
 (0)