Skip to content

Instantly share code, notes, and snippets.

@vihangpatil
Last active July 27, 2022 09:04
Show Gist options
  • Save vihangpatil/53f815a2193b54d989c4ae9e5aee9e94 to your computer and use it in GitHub Desktop.
Save vihangpatil/53f815a2193b54d989c4ae9e5aee9e94 to your computer and use it in GitHub Desktop.
Check email domains of Stripe Customers from exported CSV file
import java.io.File
data class Domain(
val fqdn: String,
val withoutTLD: String,
)
fun main() {
val emailDomainList = File("src/main/resources/customers.csv")
.readLines()
.asSequence()
.map {
Domain(
fqdn = it.split("@")[1].lowercase(),
withoutTLD = it.split("@")[1]
.split(".")[0]
.lowercase()
.replace("live", "outlook")
.replace("hotmail", "outlook")
.replace("me", "icloud")
.replace("googlemail", "gmail")
)
}
.groupBy { it.withoutTLD }
.toList()
.sortedBy { it.first }
.sortedByDescending { it.second.count() }
.toList()
println("Total emails: ${emailDomainList.sumOf { it.second.count() }}")
println("Total domains: ${emailDomainList.size}")
println("Unique domains: ${emailDomainList.count { it.second.count() == 1 }}")
println()
emailDomainList.forEach { println("${it.first} - ${it.second.count()} - ${it.second.map(Domain::fqdn).groupingBy { it }.eachCount()}") }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment