progs/yahoo.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 08 Nov 2021 01:56:57 +0000
changeset 408 95240953bf4c
parent 266 ca48ac1d3c3e
permissions -rw-r--r--
updated jars
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
import io.Source
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
import scala.util._
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
object Foo {
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
def get_data(symbol: String) : List[String] = 
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines.toList
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
def process(s: String) : String = {
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  val l = s.split(",").toList
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  l(0) + "," + l(5)
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
 }
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
def clean(sym: String) = {
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  val da = get_data(sym)
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  val out = 
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
    for (l <- da;
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
	 if l.drop(4).startsWith("-01")) yield process(l)
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  println(process(da.head))
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  out.foreach { println }
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
def main(args: Array[String]) = clean(args(0))
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
}