--- a/progs/lecture1.scala Wed Nov 08 22:36:42 2017 +0000
+++ b/progs/lecture1.scala Thu Nov 09 16:04:31 2017 +0000
@@ -302,23 +302,26 @@
// obtaining a webpage
val url = """https://nms.kcl.ac.uk/christian.urban/"""
+val url = """http://api.postcodes.io/postcodes/CR84LQ"""
Source.fromURL(url)("ISO-8859-1").mkString
-// function for looking up stockmarket data
-def price_lookup(symbol: String) : String = {
- val url = "https://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=snl1"
- Source.fromURL(url).mkString.drop(1).dropRight(2)
+// a function for looking up constituency data
+def consty_lookup(pcode: String) : String = {
+ val url = "http://api.postcodes.io/postcodes/" + pcode
+ Source.fromURL(url).mkString.split(",")(16)
}
-price_lookup("GOOG")
-price_lookup("AAPL")
+consty_lookup("CR84LQ")
+consty_lookup("WC2B4BG")
-val companies =
- List("GOOG", "AAPL", "MSFT", "IBM", "FB", "YHOO", "AMZN", "BIDU")
+val places =
+ List("CR84LQ", "WC2B4BG", "KY169QT", "CB11LY", "CB39AX")
-for (s <- companies) println(price_lookup(s))
+for (s <- places) println(consty_lookup(s))
+
+
// A Web Crawler
@@ -328,7 +331,6 @@
// regular expression "https?://[^"]*"
import io.Source
-import scala.util.matching.Regex
import scala.util._
// gets the first 10K of a web-page
@@ -358,7 +360,7 @@
// some starting URLs for the crawler
val startURL = """https://nms.kcl.ac.uk/christian.urban/"""
-//val startURL = """http://www.inf.kcl.ac.uk/staff/mcburney"""
+//val startURL = """https://nms.kcl.ac.uk/luc.moreau/index.html"""
crawl(startURL, 2)