// GET options {{{ $server = getString("server", "s2.travian.com"); $alliance = getString("alliance", null); $player = getString("player", null); $town = getString("town", null); $order = getString("order", "default"); $zoom = getString("zoom", null); $layout = getString("layout", "default"); $caption = getString("caption", $words["key"]); $groupby = getString("groupby", "player"); $colby = getString("colby", $groupby); $lines = getBool("lines"); $casen = getBool("casen"); $azoom = getBool("azoom"); $nocache = getBool("nocache"); $dotsize = getFloat("dotsize", 1); $maxdist = getInt("maxdist", null); $mindist = getInt("mindist", null); $maxpop = getInt("maxpop", null); $minpop = getInt("minpop", null); $table = preg_replace("/[^a-zA-Z0-9]/", "_", $server); $s_server = sql_escape_string($server); $server_info = sql_fetch_row(sql_query("SELECT * FROM servers WHERE name='{$s_server}'")); // }}} // figure out where we are {{{ if ($layout == "spread") { $cx = 768 / 2; $cy = 256; } else { $cx = 256; $cy = 256;
function scrapeStock($url) { $html = scraperWiki::scrape($url); $dom = new simple_html_dom(); $dom->load($html); $header = $dom->find(".stock-report-header h2", 0); if (is_null($header)) { throw new Exception("no header"); } $company = trim($header->plaintext); $trindex = 0; $years = array(); $yrs = $dom->find("table#tblRep12 tr", 2)->find("td"); if (count($yrs) <= 1) { throw new Exception("no data, skipping"); } $firstyear = intval("20" . substr(getString($yrs[1]), 0, 2)); if ($firstyear < 2000) { throw new Exception("Invalid years"); } // Resultaträkning och balansräkning $records = array(); $trindex = 0; foreach ($dom->find("table#tblRep12 tr") as $trs) { if ($trindex++ < 3) { continue; } $field = getString($trs->find("td", 0)); $skip = false; switch ($field) { case "Resultaträkning": case "Balansräkning": case "Rapportperiod": case "Datum för rapportperioden": $skip = true; break; } if ($skip) { continue; } $field = formatField($field); $tdindex = 0; foreach ($trs->find("td") as $tds) { if ($tdindex++ == 0) { continue; } $value = getFloat($tds); $year = $firstyear - $tdindex + 2; if (!array_key_exists(strval($year), $records)) { $records[strval($year)] = array('bolag' => $company, 'ar' => $year); } $records[strval($year)][$field] = $value; } } // Nyckeltal $trindex = 0; $tbls = $dom->find("table.stock-report"); $nyckeltal = $tbls[count($tbls) - 1]; foreach ($nyckeltal->find("tr") as $trs) { if ($trindex++ < 2) { continue; } $field = getString($trs->find("td", 0)); $skip = false; switch ($field) { case "ÖVRIGA": case "AVKASTNINGS- OCH MARGINALMÅTT": $skip = true; break; } if ($skip) { continue; } $field = formatField($field); $tdindex = 0; foreach ($trs->find("td") as $tds) { if ($tdindex++ == 0) { continue; } $value = getFloat($tds); $year = $firstyear - $tdindex + 2; if (!array_key_exists(strval($year), $records)) { $records[strval($year)] = array('bolag' => $company, 'ar' => $year); } $records[strval($year)][$field] = $value; } } foreach ($records as $record) { scraperwiki::save(array('bolag', 'ar'), $record); } }