Skip to content

Commit 7d11758

Browse files
committed
Implement Scala version of the fucking-coffee script using Ammonite shell
1 parent c300bc5 commit 7d11758

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scala/fucking-coffee.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************
2+
*
3+
* Get and run Ammonite (http://lihaoyi.github.io/Ammonite/#Ammonite-Shell):
4+
* $ mkdir ~/.ammonite; curl -L -o ~/.ammonite/predef.scala http://git.io/vR04f
5+
* $ curl -L -o amm http://git.io/vR08A; chmod +x amm; ./amm
6+
*
7+
* Run script:
8+
* @ load.exec("fucking-coffee.scala")
9+
*
10+
*******************************************/
11+
12+
import java.net._
13+
import java.io._
14+
import ammonite.ops._
15+
16+
val coffeeMachineIP = "10.10.42.42"
17+
val password = "1234"
18+
val passwordPrompt = "Password: "
19+
val delayBeforeBrew = 17
20+
val delay = 24
21+
22+
if ((%%who "-q").out.string.contains(sys.props("user.name"))) {
23+
24+
val telnet = new Socket(coffeeMachineIP, 23)
25+
val out = new PrintWriter(telnet.getOutputStream, true)
26+
val in = new BufferedReader(new InputStreamReader(telnet.getInputStream))
27+
28+
Thread.sleep(delayBeforeBrew * 1000);
29+
30+
if(in.readLine == passwordPrompt){
31+
out.println(password)
32+
33+
out.println("sys brew")
34+
Thread.sleep(delay * 1000)
35+
out.println("sys pour")
36+
37+
}
38+
39+
out.close()
40+
in.close()
41+
telnet.close()
42+
43+
}

0 commit comments

Comments
 (0)