Created
June 20, 2018 04:54
-
-
Save guersam/06bd3c387280f8ca55191b381ea9336c to your computer and use it in GitHub Desktop.
Check domain name availability with whois and notify via slack
This file contains hidden or 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
#!/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