Skip to content

Commit 30ca9dc

Browse files
committed
Merge pull request NARKOZ#105 from AmirKarimi/master
Implement Scala version of the fucking-coffee script
2 parents 5e63de9 + 895b922 commit 30ca9dc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scala/fucking-coffee.scala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************
2+
*
3+
* Get 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
6+
*
7+
* Run script
8+
* $ ./amm fucking-coffee.scala
9+
*
10+
*******************************************/
11+
12+
import java.net._
13+
import java.io._
14+
import ammonite.ops._
15+
import ammonite.ops.ImplicitWd._
16+
17+
val coffeeMachineIP = "10.10.42.42"
18+
val password = "1234"
19+
val passwordPrompt = "Password: "
20+
val delayBeforeBrew = 17
21+
val delay = 24
22+
23+
if ((%%who "-q").out.string.contains(sys.props("user.name"))) {
24+
25+
val telnet = new Socket(coffeeMachineIP, 23)
26+
val out = new PrintWriter(telnet.getOutputStream, true)
27+
val in = new BufferedReader(new InputStreamReader(telnet.getInputStream))
28+
29+
println(s"Wait for $delayBeforeBrew seconds")
30+
Thread.sleep(delayBeforeBrew * 1000);
31+
32+
if(in.readLine == passwordPrompt){
33+
out.println(password)
34+
35+
out.println("sys brew")
36+
Thread.sleep(delay * 1000)
37+
out.println("sys pour")
38+
39+
}
40+
41+
out.close()
42+
in.close()
43+
telnet.close()
44+
45+
}

0 commit comments

Comments
 (0)