Ever wonder how to contact individuals if all you have is their social media link (like LinkedIn, Facebook, etc)?
I was recently tasked with doing just that. Specifically, I had to take a spreadsheet and add email addresses or phone numbers to it for each row. The spreadsheets looked like this,
name,linkedin_url
Steve Wozniak,linkedin.com/in/wozniaksteve
Bill Gates,linkedin.com/in/williamhgates
...
I wasn't sure where to begin, but after some Google-fu I found an API makes this trivial. In particular, the people enrichment API for Nymeria. What's better, they have a Go SDK!
I put together a quick program to process a spreadsheet from the command line.
Setting up a go module is easy enough,
$ mkdir linkedin-enrichment
$ cd linkedin-enrichment
$ go mod init linkedin
$ go get git.nymeria.io/nymeria.go@latest
$ touch main.go
The code itself was simple. I'll let the code speak for itself (main.go below).
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
"git.nymeria.io/nymeria.go"
)
func rows(filePath string) [][]string {
f, err := os.Open(filePath)
if err != nil {
log.Fatal("Unable to read input file "+filePath, err)
}
defer f.Close()
csvReader := csv.NewReader(f)
records, err := csvReader.ReadAll()
if err != nil {
log.Fatal("Unable to parse file as CSV for "+filePath, err)
}
return records
}
func main() {
nymeria.SetAuth("YOUR API KEY GOES HERE")
rs := rows("YOUR FILE NAME HERE")
// Note, [1:] to skip the header row.
for _, row := range rs[1:] {
params := []nymeria.EnrichParams{
{
// In my case, the URL was in the second column.
URL: row[1],
},
}
if es, err := nymeria.Enrich(params...); err == nil {
for _, enrichment := range es {
if enrichment.Status == "success" {
if len(enrichment.Data.Emails) != 0 {
fmt.Printf("%s,%s\n", row[1], enrichment.Data.Emails[0].Address)
}
}
}
}
}
}
Running and getting the output is simple,
➜ linkedin-enrichment: go run main.go
linkedin.com/in/wozniaksteve,steve@woz.org
linkedin.com/in/williamhgates,bill.gates@gatesfoundation.org
Has anyone else been tasked with similar problems? How did you solve them?
Top comments (0)