Skip to content

Commit

Permalink
data IO WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
BinarySoftware committed Jun 25, 2019
1 parent 2fda33f commit f662b0d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/main/scala/DataManager/dataManager.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import scala.io.Source
import ScalarStocks._
import java.io._

object DataManager {
def getDataFromURLWithSymbols(urlString: String, symbols: Array[String]) : String = {
Expand All @@ -14,11 +15,16 @@ object DataManager {
}
}

def saveDataToLocalFile() : String = {
return "Success"
def saveDataToLocalFile() : Unit= {
val writer = new PrintWriter(new File("symbols.txt"))
val dataToWrite = symbols.mkString("\n")
writer.write(dataToWrite)
writer.close()
}

def loadDataFromLocalFile() : String = {
return "Success"
def loadDataFromLocalFile() : Unit = {
for (line <- Source.fromFile("symbols.txt").getLines()) {
symbols :+= line
}
}
}
3 changes: 3 additions & 0 deletions src/main/scala/UI/applicationUI.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PublicDef._
import java.util.Date
import ScalarStocks._
import DataManager._

object AppUI {
def makeMainUI(symbols: Option[List[Symbol]]) : Unit = {
Expand Down Expand Up @@ -46,6 +47,7 @@ object AppUI {
makeControlsForMainScreen()
} else {
symbols :+= symbolName
saveDataToLocalFile()
refreshData(symbols)
}
} else if (action == "D" || action == "d") {
Expand All @@ -55,6 +57,7 @@ object AppUI {

if (symbols.contains(symbolName)) {
symbols = symbols.filter(! _.contains(symbolName))
saveDataToLocalFile()
refreshData(symbols)
} else {
println(Console.RED + "Sorry, there is no " + symbolName + " in your symbols array")
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/scalarStocks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import AppUI._
object ScalarStocks {

val stocksAPIURL = "https://ws-api.iextrading.com/1.0/tops/last?symbols="
var symbols = Array("AAPL","MSFT","TSLA","IBM","LLY")
var symbols: Array[String] = Array()

def main(args: Array[String]) : Unit = {
makeLaunchScreen()
loadDataFromLocalFile()
refreshData(symbols)
}

Expand Down
7 changes: 7 additions & 0 deletions symbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MSFT
TSLA
LLY
INTC
AAPL
BAB
AMD

0 comments on commit f662b0d

Please sign in to comment.