Skip to content

Commit

Permalink
Merge dni into master
Browse files Browse the repository at this point in the history
  • Loading branch information
osvik committed May 9, 2018
2 parents f28ae9d + f704cd5 commit 2089472
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Scan a file, like for example a sitemap.xml file, for urls:

This feature is useful to create files with urls to use with [check-my-pages](https://github.com/greenpeace/check-my-pages).

#### Scan Spanish ID numbers

Scan Spanish ID numbers (DNI or NIE)

```bash
./ecounter -input=rawfile.csv -count=dnis -output=uniques.txt
```

#### Hash emails (encrypt)

```bash
Expand Down
7 changes: 7 additions & 0 deletions ecounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const emailRegex string = `([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]

const shaRegex string = `[A-Fa-f0-9]{64}`

const dninieRegex string = `[A-z]?\d{7,8}[TRWAGMYFPDXBNJZSQVHLCKEtrwagmyfpdxbnjzsqvhlcke]`

const urlsRegex string = `https?://([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/?`

var debug *bool
Expand All @@ -37,6 +39,7 @@ func main() {

var allMatches []string
var allMatchesLC []string
var allMatchesUC []string
var uniques []string

switch *countIt {
Expand All @@ -51,6 +54,10 @@ func main() {
case "urls":
allMatches = searchInString(fileToHandle, urlsRegex)
uniques = uniquesInArray(allMatches)
case "dnis":
allMatches = searchInString(fileToHandle, dninieRegex)
allMatchesUC = arrayToUpercase(allMatches)
uniques = uniquesInArray(allMatchesUC)
default:
allMatches = searchInString(fileToHandle, emailRegex)
allMatchesLC = arrayToLowercase(allMatches)
Expand Down
11 changes: 11 additions & 0 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ func arrayToLowercase(a []string) []string {
return result
}

// arrayToUpercase Upercases all the items in an array.
func arrayToUpercase(a []string) []string {
defer timeTrack(time.Now(), "arrayToUpercase")
var result []string
for _, v := range a {
lv := strings.ToUpper(v)
result = append(result, lv)
}
return result
}

//uniquesInArray Finds uniques in an array and returns.
func uniquesInArray(a []string) []string {
defer timeTrack(time.Now(), "uniquesInArray")
Expand Down
2 changes: 1 addition & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Use the options as in this example:
-help Display this help
-input=rawfile.csv Define the input file as rawfile.csv
-count=emails What to count in the file. It can be "emails", "sha256" or "urls". By default it counts emails.
-count=emails What to count in the file. It can be "emails", "sha256", "urls" or "dnis". By default it counts emails.
-output=uniques.txt Define the output file as uniques.txt
-encrypt=true Encrypt the results as sha256, to upload to Google Adwords
-debug=true Debug the script
Expand Down

0 comments on commit 2089472

Please sign in to comment.