Skip to content

Commit

Permalink
Show more information (title name, location)
Browse files Browse the repository at this point in the history
Add option to not convert to email
Add debug
  • Loading branch information
nodauf committed Jan 4, 2022
1 parent 42bbd18 commit 2401c16
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/cmd/gather/linkedin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gather
import (
"GoMapEnum/src/linkedin"
"GoMapEnum/src/logger"
"errors"

"github.com/spf13/cobra"
)
Expand All @@ -16,6 +17,12 @@ var linkedinCmd = &cobra.Command{
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.
The session cookie is needed to use the Linkedin features.`,
Example: `go run main.go gather linkedin -c contoso -f "{f}{last}@contonso.com" -e -s AQEDA...`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if linkedinOptions.Format == "" && linkedinOptions.Email {
return errors.New("format flag is requre when email should be guess")
}
return nil
},
Run: func(cmdCli *cobra.Command, args []string) {
log := logger.New("Gather", "linkedin", "Linkedin")
log.SetLevel(level)
Expand All @@ -30,9 +37,9 @@ func init() {

linkedinCmd.Flags().StringVarP(&linkedinOptions.Format, "format", "f", "", "Format (ex:{first}.{last}@domain.com, domain\\{f}{last}")
linkedinCmd.Flags().StringVarP(&linkedinOptions.Company, "company", "c", "", "Company name")
linkedinCmd.Flags().BoolVar(&linkedinOptions.Email, "email", true, "Guess the email according to the format. If false print the first name and last name")
linkedinCmd.Flags().BoolVarP(&linkedinOptions.ExactMatch, "exactMatch", "e", false, "Exact match of the company's name")
linkedinCmd.Flags().StringVarP(&linkedinOptions.Cookie, "cookie", "s", "", "Session cookie named li_at")
linkedinCmd.MarkFlagRequired("company")
linkedinCmd.MarkFlagRequired("cookie")
linkedinCmd.MarkFlagRequired("format")
}
2 changes: 2 additions & 0 deletions src/linkedin/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (options *Options) Gather() []string {
options.Company = strings.ToLower(options.Company)
// Get all the companies from the option
companies := options.getCompany()
log.Debug("Found " + strconv.Itoa(len(companies.Elements)) + " companies matching " + options.Company)
for _, company := range companies.Elements {
// Extract the company name from the struct
companyLinkedinName := strings.ToLower(company.EntityLockupView.Title.Text)
Expand All @@ -29,6 +30,7 @@ func (options *Options) Gather() []string {
companyID, _ := strconv.Atoi(strings.Split(company.EntityLockupView.TrackingUrn, ":")[3])
// Get the people of the company, starting from 0
output = options.getPeople(companyID, 0)
log.Debug("Found " + strconv.Itoa(len(output)) + " peoples for " + options.Company)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/linkedin/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var log *logger.Logger
// Options for o365 module
type Options struct {
Format string
Email bool
ExactMatch bool
Cookie string
utils.BaseOptions
Expand Down
14 changes: 10 additions & 4 deletions src/linkedin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (options *Options) getCompany() linkedinListCompany {
return companies
}
json.Unmarshal([]byte(body), &companies)
log.Debug("Found " + strconv.Itoa(len(companies.Elements)) + " companies matching " + options.Company)
return companies
}

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

numberPeople = len(element.Results)
log.Debug("Found " + strconv.Itoa(numberPeople) + " from " + strconv.Itoa(start) + " for " + options.Company)
for _, people := range element.Results {
// if it is an anonymous user, skip it
if people.Title.Text == "LinkedIn Member" {
continue
}
// Parse the name to output in the specified format
name := strings.Split(people.Title.Text, " ")
// If the name is composed of more than 2 words, we skip it
if len(name) == 2 {
// If the name is composed of more than 2 words or the email should not be guessed, we skip it
if len(name) == 2 && options.Email {
var email string
email = options.Format
log.Verbose(name[0] + " - " + name[1])
Expand All @@ -81,9 +81,15 @@ func (options *Options) getPeople(companyID, start int) []string {
email = strings.ReplaceAll(email, "{last}", name[1])
email = strings.ReplaceAll(email, "{l}", name[1][0:1])
email = strings.ToLower(email)
log.Success(email + " - " + people.PrimarySubtitle.Text + "-" + people.SecondarySubtitle.Text)
log.Success(email + " - " + people.PrimarySubtitle.Text + " - " + people.SecondarySubtitle.Text)
output = append(output, email)
}
if !options.Email {
result := people.Title.Text + " - " + people.PrimarySubtitle.Text + " - " + people.SecondarySubtitle.Text
log.Success(result)
output = append(output, result)

}

}
}
Expand Down

0 comments on commit 2401c16

Please sign in to comment.