$s = explode("\n", $s); checkTyp($rec = getRec($s), 'T'); echo $flnm . ":<br>\nThis is " . (substr($rec, 27, 1) == 'T' ? 'a <b style="color:orange;">TEST</b> file.' : 'NOT a test file.') . "<br>\n"; checkTyp(getRec($s), 'A'); $tot = 0; while (typ($rec = getRec($s)) == 'B') { $amt = amt($rec); $tot += $amt; //echo "amt=$amt tot=$tot<br>\n"; } checkTyp($rec, 'C'); $amt = amt($rec, FALSE); if ($amt != $tot) { err("bad C total amt={$amt} tot={$tot}"); } checkTyp($rec = getRec($s), 'K'); $amt = amt($rec, FALSE); if ($amt != $tot) { err("bad K total amt={$amt} tot={$tot}"); } echo 'File looks <b style="color:lightgreen;">GOOD</b>! Total = $' . number_format($tot / 100, 2); function checkTyp($rec, $typ) { if (typ($rec) != $typ) { err('missing ' . $typ); } } function typ($rec) { return substr($rec, 0, 1); }
function getNews() { $html = scraperWiki::scrape("http://di.se/Bors--Marknad/Borstips/"); $dom = new simple_html_dom(); $dom->load($html); $foundlinks = array(); $i = 0; foreach ($dom->find(".table-article-list a") as $link) { //if ($i++<60) // continue; try { $url = $link->href; //print_r(getPlaintext($link) . " " . $url . "\n"); $objs = getRec($url); foreach ($objs as $obj) { //print_r($obj); if (is_null($obj["stock"])) { throw new Exception("Stock saknas " . $url); } if (is_null($obj["by"])) { throw new Exception("By saknas " . $url); } if (is_null($obj["date"])) { throw new Exception("Date saknas " . $url); } //print_r (json_encode($obj) . "\n"); scraperwiki::save(array('stock', 'by', 'date'), $obj); } } catch (Exception $e) { print "Error: " . $e->getMessage() . "\n"; } } }