Skip to content

Instantly share code, notes, and snippets.

@guersam
Created June 20, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guersam/06bd3c387280f8ca55191b381ea9336c to your computer and use it in GitHub Desktop.
Save guersam/06bd3c387280f8ca55191b381ea9336c to your computer and use it in GitHub Desktop.
Check domain name availability with whois and notify via slack
#!/usr/bin/env amm
import $ivy.`com.github.gilbertw1::slack-scala-client:0.2.3`
import slack.api.BlockingSlackApiClient
import akka.actor.ActorSystem
import scala.util.Try
def sendSlackNotification(msg: String)(implicit sys: ActorSystem): Unit = {
val token = "<token>" // TODO parameterize
val client = BlockingSlackApiClient(token)
client.postChatMessage(
channelId = "auto_notifications",
text = msg,
linkNames = Some("true"),
)
}
val AvailPat = "^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri|domain was not found".r
def isAvailble(domain: String): Boolean = {
import scala.sys.process._
Try {
s"whois $domain".!!.split("\n").exists(line => AvailPat.findFirstIn(line).nonEmpty)
}.getOrElse(false)
}
@main
def main(domains: String*): Unit = {
implicit val system = ActorSystem("check-domain")
if (domains.isEmpty) {
println("domains required")
} else {
println(s"Checking domain name availablities for ${domains.mkString(", ")}")
domains.foreach { d =>
if (isAvailble(d)) {
println(s"Domain name $d is available!")
sendSlackNotification(
s"""Domain name $d is availble! @guersam
|Go get here: https://www.namecheap.com/domains/registration/results.aspx?domain=$d
|""".stripMargin.trim
)
} else {
println(s"Domain name $d is not availble.")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment