Skip to content

Implement Scala version of the fucking-coffee script #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions scala/fucking-coffee.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************
*
* Get Ammonite (http://lihaoyi.github.io/Ammonite/#Ammonite-Shell):
* $ mkdir ~/.ammonite; curl -L -o ~/.ammonite/predef.scala http://git.io/vR04f
* $ curl -L -o amm http://git.io/vR08A; chmod +x amm
*
* Run script
* $ ./amm fucking-coffee.scala
*
*******************************************/

import java.net._
import java.io._
import ammonite.ops._
import ammonite.ops.ImplicitWd._

val coffeeMachineIP = "10.10.42.42"
val password = "1234"
val passwordPrompt = "Password: "
val delayBeforeBrew = 17
val delay = 24

if ((%%who "-q").out.string.contains(sys.props("user.name"))) {

val telnet = new Socket(coffeeMachineIP, 23)
val out = new PrintWriter(telnet.getOutputStream, true)
val in = new BufferedReader(new InputStreamReader(telnet.getInputStream))

println(s"Wait for $delayBeforeBrew seconds")
Thread.sleep(delayBeforeBrew * 1000);

if(in.readLine == passwordPrompt){
out.println(password)

out.println("sys brew")
Thread.sleep(delay * 1000)
out.println("sys pour")

}

out.close()
in.close()
telnet.close()

}