Last active
July 27, 2022 09:04
-
-
Save vihangpatil/53f815a2193b54d989c4ae9e5aee9e94 to your computer and use it in GitHub Desktop.
Check email domains of Stripe Customers from exported CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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