} # Download XMls - voting records from Spain's Congreso require 'scraperwiki/simple_html_dom.php'; //temp //first voting records are from 2012 //scraperwiki::save_var('last_date','2012-01-01'); //scraperwiki::save_var('last_date','2012-05-23'); $date = new DateTime(scraperwiki::get_var('last_date')); $today = new DateTime(); while ($date < $today) { //echo $date->format('U = Y-m-d H:i:s') . "\n"; $url = "http://www.congreso.es/portal/page/portal/Congreso/Congreso/Actualidad/Votaciones?fechaSeleccionada=" . $date->format('Y/m/d'); $html = scraperwiki::scrape($url); $dom = new simple_html_dom(); $dom->load($html); $right_date = compare_dates($dom, $date); //if current date <= last date of votes, do; otherwise do nothing, no new votes if ($right_date) { $url = "http://www.congreso.es/portal/page/portal/Congreso/Congreso/Actualidad/Votaciones?fechaSeleccionada=" . $right_date->format('Y/m/d'); $html0 = scraperwiki::scrape($url); $dom = new simple_html_dom(); echo strlen($html0); //problem with scraperwiki with long page: if (strlen($html0) > 200000) { $strip = get_first_string($html0, '<DIV class="votacionesEncabezado">', 'mostrarCapa( "capaLegislaturas", "true" );'); $htmls = returnSubstrings($strip, '<TABLE>', '</TABLE>'); foreach ($htmls as $key => $html) { $htmls[$key] = '<html><body><div class="votacionesResultado"><table>' . $htmls[$key] . '</table></div></body></html>'; } } else { $htmls = array($html);
// Starting the session session_start(); // Store create a child information $code = $_POST['code']; $birthdate = $_POST['birthdate']; // Get JSON info using code $results = json_decode(file_get_contents('https://ped-akido.herokuapp.com/patients?mrn=' . $code), true); $child = $results['patients']; // If child does not exist if (count($child) == 0) { $_SESSION['messages'] = 7; header('Location: add_child/'); exit; } else { // Compare birthdate to JSON birthdate if (!compare_dates($birthdate, $child[0]['birthdate'])) { // Birthdates did not match $_SESSION['messages'] = 6; header('Location: add_child/'); exit; } else { // SQL Statement that looks up user in database $sqlSteal = 'SELECT * FROM ' . T2 . ' WHERE child_id = "' . $code . '"'; $sql = 'INSERT INTO ' . T2 . ' (user_id, child_id, age_group) values ("' . $_SESSION['user_id'] . '", "' . $code . '", "' . age_group($birthdate) . '")'; $database = mysqli_connect(HOST, USER, PW, DB); // Checks if connection worked if (mysqli_connect_error() != 0) { die("Error connecting to the database. The error is: " . mysqli_connect_error()); } // Look up table and store results $results = mysqli_query($database, $sql);