Skip to content

Instantly share code, notes, and snippets.

@itsmingjie
Last active March 17, 2019 22:10
Show Gist options
  • Save itsmingjie/6adf063ce9b7f8b5169690f0df182349 to your computer and use it in GitHub Desktop.
Save itsmingjie/6adf063ce9b7f8b5169690f0df182349 to your computer and use it in GitHub Desktop.
This bad boy uses the script from https://github.com/hodgesmr/FindGitHubEmail/ to find the best guess of email addresses for a list of GitHub users in batch.
/*
This bad boy uses the script from https://github.com/hodgesmr/FindGitHubEmail/
to find the best guess of email addresses for a list of GitHub users in batch.
Known problem: GitHub throws an IP ban if you try to access its API for too many times. Usually
they'll ban you within 30 calls, but if you're lucky, who knows ;) Use a VPN.
Before running: grant executable permission to the findGitHubEmail script.
Source file format: plain text, one username per line.
Hacky stuff written for Hack Club (hackclub.com).
*/
package main
import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"os/exec"
"strconv"
"strings"
"time"
)
const startAt = 0 // index of user for the program to start at
const sourceFile = "source" // source file name
const outputFile = "result.csv" // file name for the target output
const minWait = 1000 // min time (ms) to wait before processing next username
const maxWait = 10000 // max time (ms) to wait before processing next username
func main() {
src, err := ioutil.ReadFile(sourceFile)
if err != nil {
fmt.Printf("Unfound file")
log.Fatal(err)
}
s := strings.Split(string(src), "\n")
for i, u := range s {
if i < startAt {
continue
}
cmdName := "./findGitHubEmail"
out, _ := exec.Command(cmdName, u).Output()
r := rand.Intn(maxWait-minWait) + minWait
fmt.Println("On #" + strconv.Itoa(i) + " (" + u + "). Sleeping " + strconv.Itoa(r/1000) + " seconds.")
time.Sleep(time.Duration(r) * time.Millisecond)
newStr := strconv.Itoa(i) + ", " + u + ", " + string(out[:])
if len(out) == 0 {
newStr += "\n"
}
addToFile(outputFile, newStr)
}
}
// adds a new line into the file
func addToFile(fileName, newLine string) {
o, err := ioutil.ReadFile(fileName)
if err != nil {
log.Fatal(err)
}
oStr := string(o)
oStr += newLine
ioutil.WriteFile(fileName, []byte(oStr), 0666)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment