lead-list-dedupe 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +52 -0
- data/bin/lead-list-dedupe +25 -0
- data/lib/lead_list_dedupe.rb +103 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 94f3ec11df4c2db854d4a525444334d15ab8fd1803f46dc1eaab5338f74d7987
|
|
4
|
+
data.tar.gz: 46e3a6dfeddb820b700536053d901644cd87a01f59dd2e6e56a4ebbae5d5b2f2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 17f3ec0edf404d72dc2306f0b979aa560f1a08e1e7e959585f81a344550c7a652a480538fa0d6de3e05dd7192223ef57110f95683430331da4edb004c5923644
|
|
7
|
+
data.tar.gz: a08fe58080fa6f86a55c8276971206c40cfba2ea9f84b64563dbf4e5c22351d3b15312065498ee10941388d9c8477dfb12d495595241996684624bde21374a8c
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OneGTMLab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# lead-list-dedupe
|
|
2
|
+
|
|
3
|
+
A Ruby command-line tool that normalises and de-duplicates a CSV lead list before it is imported into a CRM or a sequencer.
|
|
4
|
+
It cleans whitespace, lower-cases emails, reduces LinkedIn URLs to one canonical form, reduces websites to bare domains,
|
|
5
|
+
and then removes duplicates, **filling blank fields in the surviving row from the duplicates it removes**. Ruby standard library only (`csv`, `uri`).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bin/lead-list-dedupe examples/leads.csv --out clean.csv --dupes removed.csv
|
|
9
|
+
# input 5 kept 3 duplicates 2
|
|
10
|
+
# matched on: email="Email" linkedin="LinkedIn" domain="Website" name="First Name+Last Name"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Column names are detected case-insensitively (`email`, `work_email`; `linkedin`, `linkedin_url`; `domain`, `website`; `first_name` + `last_name` or `name`).
|
|
14
|
+
|
|
15
|
+
## How rows are matched
|
|
16
|
+
|
|
17
|
+
A row is a duplicate of an earlier row when **any one** of these keys matches, checked in this order:
|
|
18
|
+
|
|
19
|
+
1. normalised email
|
|
20
|
+
2. normalised LinkedIn profile or company URL (`https://www.linkedin.com/in/<slug>`: query string, trailing slash, country sub-domain and case are removed)
|
|
21
|
+
3. full name plus company domain
|
|
22
|
+
|
|
23
|
+
Name plus domain is a signal, not proof: two different people can share both, so look at `--dupes` (which lists the row each duplicate matched)
|
|
24
|
+
before you trust a large removal. This is also why the tool keeps the first row and reports, rather than deleting silently.
|
|
25
|
+
|
|
26
|
+
## Example (live run, 27 Nov 2026, `examples/leads.csv`)
|
|
27
|
+
|
|
28
|
+
| input row | what happened |
|
|
29
|
+
|---|---|
|
|
30
|
+
| 2 Jane Doe `Jane@Example.com` | kept; email lower-cased, domain reduced to `example.com` |
|
|
31
|
+
| 3 Jane Doe `jane@example.com` | removed, matched row 2 on email; its Title `VP Sales` fills the blank Title on row 2 |
|
|
32
|
+
| 4 Sam Roe (LinkedIn only) | kept |
|
|
33
|
+
| 5 Samuel Roe (same LinkedIn, plus an email) | removed, matched row 4 on LinkedIn URL; its email fills the blank on row 4 |
|
|
34
|
+
| 6 Kim Wu | kept |
|
|
35
|
+
|
|
36
|
+
## Why it matters
|
|
37
|
+
|
|
38
|
+
Duplicate records split activity history, double-send to the same person and inflate list counts.
|
|
39
|
+
OneGTMLab's glossary has the background on [deduplication](https://www.onegtmlab.dev/glossary/deduplication) and
|
|
40
|
+
[data hygiene](https://www.onegtmlab.dev/glossary/data-hygiene).
|
|
41
|
+
If the list came out of a sourcing API, the directory reviews eleven of them, with plans, rate limits and MCP support read from the vendors' own pages:
|
|
42
|
+
[Sourcing APIs](https://www.onegtmlab.dev/tool-directory/sourcing).
|
|
43
|
+
|
|
44
|
+
## Test
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
ruby test/test_dedupe.rb
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Licence
|
|
51
|
+
|
|
52
|
+
MIT. Made by [OneGTMLab](https://www.onegtmlab.dev), GTM engineering for B2B teams.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "json"
|
|
6
|
+
require_relative "../lib/lead_list_dedupe"
|
|
7
|
+
|
|
8
|
+
opts = { out: nil, dupes: nil }
|
|
9
|
+
OptionParser.new do |o|
|
|
10
|
+
o.banner = "usage: lead-list-dedupe leads.csv [--out clean.csv] [--dupes dupes.csv] [--json]"
|
|
11
|
+
o.on("--out FILE", "write the cleaned, de-duplicated CSV") { |v| opts[:out] = v }
|
|
12
|
+
o.on("--dupes FILE", "write the removed duplicates, with the row each one matched") { |v| opts[:dupes] = v }
|
|
13
|
+
o.on("--json", "print the report as JSON") { opts[:json] = true }
|
|
14
|
+
end.parse!
|
|
15
|
+
path = ARGV.first or abort("missing input CSV")
|
|
16
|
+
table = CSV.read(path, headers: true, encoding: "bom|utf-8")
|
|
17
|
+
kept, dupes, report = LeadListDedupe.run(table)
|
|
18
|
+
LeadListDedupe.write_csv(opts[:out], kept, table.headers) if opts[:out]
|
|
19
|
+
LeadListDedupe.write_csv(opts[:dupes], dupes, table.headers + %w[duplicate_of_row input_row]) if opts[:dupes]
|
|
20
|
+
if opts[:json]
|
|
21
|
+
puts JSON.generate(report)
|
|
22
|
+
else
|
|
23
|
+
puts "input #{report[:input]} kept #{report[:kept]} duplicates #{report[:duplicates]}"
|
|
24
|
+
puts "matched on: #{report[:columns].map { |k, v| "#{k}=#{v.inspect}" }.join(' ')}"
|
|
25
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "csv"
|
|
4
|
+
require "uri"
|
|
5
|
+
|
|
6
|
+
# Normalise and de-duplicate a CSV lead list. Standard library only.
|
|
7
|
+
module LeadListDedupe
|
|
8
|
+
VERSION = "0.1.0"
|
|
9
|
+
|
|
10
|
+
EMAIL_COLS = %w[email work_email email_address].freeze
|
|
11
|
+
LINKEDIN_COLS = %w[linkedin linkedin_url linkedin_profile profile_url person_linkedin_url].freeze
|
|
12
|
+
DOMAIN_COLS = %w[domain company_domain website company_website].freeze
|
|
13
|
+
FIRST_COLS = %w[first_name firstname].freeze
|
|
14
|
+
LAST_COLS = %w[last_name lastname].freeze
|
|
15
|
+
NAME_COLS = %w[name full_name].freeze
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
def find_col(headers, candidates)
|
|
20
|
+
headers.find { |h| candidates.include?(h.to_s.strip.downcase.tr(" ", "_")) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def clean_text(v)
|
|
24
|
+
v.to_s.gsub(/[[:space:]]+/, " ").strip
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def norm_email(v)
|
|
28
|
+
e = clean_text(v).downcase.sub(/\Amailto:/, "")
|
|
29
|
+
e.match?(/\A[^@\s]+@[^@\s]+\.[^@\s.]+\z/) ? e : ""
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# https://www.linkedin.com/in/jane-doe-123/?utm=x -> https://www.linkedin.com/in/jane-doe-123
|
|
33
|
+
def norm_linkedin(v)
|
|
34
|
+
s = clean_text(v)
|
|
35
|
+
return "" if s.empty?
|
|
36
|
+
s = "https://#{s}" unless s.match?(%r{\Ahttps?://}i)
|
|
37
|
+
uri = URI.parse(s) rescue (return "")
|
|
38
|
+
return "" unless uri.host.to_s.downcase.end_with?("linkedin.com")
|
|
39
|
+
m = uri.path.to_s.match(%r{\A/(in|company)/([^/]+)}i)
|
|
40
|
+
return "" unless m
|
|
41
|
+
"https://www.linkedin.com/#{m[1].downcase}/#{URI.decode_www_form_component(m[2]).downcase}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def norm_domain(v)
|
|
45
|
+
s = clean_text(v).downcase
|
|
46
|
+
return "" if s.empty?
|
|
47
|
+
s = s.sub(%r{\A[a-z][a-z0-9+.-]*://}, "").sub(/\Awww\./, "")
|
|
48
|
+
s.split(%r{[/?#]}).first.to_s.sub(/:\d+\z/, "")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def field(row, col)
|
|
52
|
+
col ? row[col] : nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Returns [clean_rows, duplicate_rows, report]
|
|
56
|
+
def run(table)
|
|
57
|
+
headers = table.headers
|
|
58
|
+
ec = find_col(headers, EMAIL_COLS)
|
|
59
|
+
lc = find_col(headers, LINKEDIN_COLS)
|
|
60
|
+
dc = find_col(headers, DOMAIN_COLS)
|
|
61
|
+
fc = find_col(headers, FIRST_COLS)
|
|
62
|
+
xc = find_col(headers, LAST_COLS)
|
|
63
|
+
nc = find_col(headers, NAME_COLS)
|
|
64
|
+
|
|
65
|
+
index = {}
|
|
66
|
+
kept = []
|
|
67
|
+
kept_input_row = []
|
|
68
|
+
dupes = []
|
|
69
|
+
table.each_with_index do |orig, i|
|
|
70
|
+
row = orig.to_h.transform_values { |v| clean_text(v) }
|
|
71
|
+
row[ec] = norm_email(row[ec]) if ec
|
|
72
|
+
row[lc] = norm_linkedin(row[lc]) if lc
|
|
73
|
+
row[dc] = norm_domain(row[dc]) if dc
|
|
74
|
+
name = clean_text(nc ? row[nc] : [fc && row[fc], xc && row[xc]].compact.join(" ")).downcase
|
|
75
|
+
domain = dc ? row[dc] : (ec && row[ec].to_s.include?("@") ? row[ec].split("@").last : "")
|
|
76
|
+
keys = []
|
|
77
|
+
keys << "email:#{row[ec]}" if ec && !row[ec].to_s.empty?
|
|
78
|
+
keys << "li:#{row[lc]}" if lc && !row[lc].to_s.empty?
|
|
79
|
+
keys << "nd:#{name}|#{domain}" if !name.empty? && !domain.to_s.empty?
|
|
80
|
+
hit = keys.map { |k| index[k] }.compact.first
|
|
81
|
+
if hit
|
|
82
|
+
merged = kept[hit]
|
|
83
|
+
row.each { |k, v| merged[k] = v if merged[k].to_s.empty? && !v.to_s.empty? }
|
|
84
|
+
dupes << row.merge("duplicate_of_row" => kept_input_row[hit], "input_row" => i + 2)
|
|
85
|
+
keys.each { |k| index[k] ||= hit }
|
|
86
|
+
else
|
|
87
|
+
kept << row
|
|
88
|
+
kept_input_row << i + 2
|
|
89
|
+
keys.each { |k| index[k] = kept.size - 1 }
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
report = { input: table.size, kept: kept.size, duplicates: dupes.size,
|
|
93
|
+
columns: { email: ec, linkedin: lc, domain: dc, name: nc || [fc, xc].compact.join("+") } }
|
|
94
|
+
[kept, dupes, report]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def write_csv(path, rows, headers)
|
|
98
|
+
CSV.open(path, "w") do |csv|
|
|
99
|
+
csv << headers
|
|
100
|
+
rows.each { |r| csv << headers.map { |h| r[h].to_s.empty? ? nil : r[h] } }
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lead-list-dedupe
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jainendra Ojha
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: "Ruby CLI that normalises and de-duplicates a CSV lead list by email, canonical LinkedIn URL and name plus domain, filling blanks from the removed duplicates."
|
|
13
|
+
email:
|
|
14
|
+
- account@onegtmlab.dev
|
|
15
|
+
executables:
|
|
16
|
+
- lead-list-dedupe
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- bin/lead-list-dedupe
|
|
23
|
+
- lib/lead_list_dedupe.rb
|
|
24
|
+
homepage: "https://www.onegtmlab.dev/tool-directory/sourcing"
|
|
25
|
+
licenses:
|
|
26
|
+
- MIT
|
|
27
|
+
metadata:
|
|
28
|
+
source_code_uri: "https://github.com/jaizendra-netizen/lead-list-dedupe"
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
-
|
|
35
|
+
- ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: "2.7"
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
-
|
|
41
|
+
- ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: "0"
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 4.1.0
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: "Ruby CLI that normalises and de-duplicates a CSV lead list by email, canonical LinkedIn URL and name plus domain, filling blanks from the re"
|
|
48
|
+
test_files: []
|