- Professional Scala
- Mads Hartmann Ruslan Shevchenko
- 277字
- 2021-07-23 17:24:22
Obtaining the Time Request from Our Chatbot Program
For now, let's return to our task: modifying the chatbot
program so that it replies with the current time, as requested by the use of time
. Let's learn how to do this:
Steps for C ompletion
- Check for
time
to match the statement:case "time" =>
- Retrieve the current time using the Java API. Use the
now
method ofjava.time.LocalTime
:java.time.LocalTime.now()
- Display the output of the time using string interpolators, as follows:
println("time is ${java.time.LocalTime.now()}")
The main
method will look like this:
def main(args: Array[String]): Unit = { val name = StdIn.readLine("Hi! What is your name?") println(s" $name, tell me something interesting, say 'bay' to end the talk") var timeToBye = false while (!timeToBye)timeToBye = StdIn.readLine(">") match {case "bye" => println("ok, bye")truecase "time" => println(s"time is ${java.time.LocalTime.now()}")truecase _ => println("interesting...")false} }
After we prepare and package our artifacts, we need to run them as well.
In this book, we will use the running system from unpackaged sources via sbt
(as in the early days of Ruby applications), assuming that sources and sbt
tools are accessible from the production environment. Using this, we can use build tool commands for sources such as sbt run
. In real life, packaging for production is a bit more complex.
Popular methods for doing this are as follows:
- Preparing a fat jar (which includes all dependencies). An
sbt
plugin for this exists, which can be found at the following link: https://github.com/sbt/sbt-assembly. - Preparing a native system package (which includes jars, dependencies, custom layouts, and so on). There is also an
sbt
plugin to create native system packages, which can be found at the following link: https://github.com/sbt/sbt-native-packager.
推薦閱讀
- 黑客攻防實戰技術完全手冊:掃描、嗅探、入侵與防御
- SOA用戶指南
- 網管員典藏書架:網絡管理與運維實戰寶典
- INSTANT PhpStorm Starter
- 物聯網之魂:物聯網協議與物聯網操作系統
- Hands-On Chatbots and Conversational UI Development
- Web Application Development with R Using Shiny
- WordPress 5 Complete
- Wireshark網絡分析就這么簡單
- 電力物聯網工程技術原理與應用
- 雷達饋線技術
- Yii Application Development Cookbook(Second Edition)
- Learning Storm
- Cisco無線局域網配置基礎
- 算力網絡:云網融合2.0時代的網絡架構與關鍵技術