Beispiel #1
0
<?php

use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Net;
$sanity = array('re.findall' => 'You should use re.findall() to extract the numbers');
// Compute the stuff for the output
$code = $USER->id + $LINK->id + $CONTEXT->id;
$sample_url = dataUrl('regex_sum_42.txt');
$actual_url = dataUrl('regex_sum_' . $code . '.txt');
$sample_data = Net::doGet($sample_url);
$sample_count = strlen($sample_data);
$response = Net::getLastHttpResponse();
if ($response != 200) {
    die("Response={$response} url={$sample_url}");
}
$actual_data = Net::doGet($actual_url);
$actual_count = strlen($actual_data);
$response = Net::getLastHttpResponse();
if ($response != 200) {
    die("Response={$response} url={$actual_url}");
}
$actual_matches = array();
preg_match_all('/[0-9]+/', $actual_data, $actual_matches);
$actual_count = count($actual_matches[0]);
$actual_sum = 0;
foreach ($actual_matches[0] as $match) {
    $actual_sum = $actual_sum + $match;
}
$sample_matches = array();
preg_match_all('/[0-9]+/', $sample_data, $sample_matches);
Beispiel #2
0
<?php

require_once 'data_util.php';
use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
$sanity = array('urllib' => 'You should use urllib to retrieve the data from the URL', 'json' => 'You should use json to parse the data retrieved from the URL');
// A random code
$code = $USER->id + $LINK->id + $CONTEXT->id;
// Set the data URLs
$sample_url = dataUrl('comments_42.json');
$actual_url = dataUrl('comments_' . $code . '.json');
// Compute the sum data
$json = getJsonOrDie(dataUrl('comments_42.json'));
$sum_sample = sumCommentJson($json);
$json = getJsonOrDie(dataUrl('comments_' . $code . '.json'));
$sum = sumCommentJson($json);
$oldgrade = $RESULT->grade;
if (isset($_POST['sum']) && isset($_POST['code'])) {
    $RESULT->setJsonKey('code', $_POST['code']);
    if ($_POST['sum'] != $sum) {
        $_SESSION['error'] = "Your sum did not match";
        header('Location: ' . addSession('index.php'));
        return;
    }
    $val = validate($sanity, $_POST['code']);
    if (is_string($val)) {
        $_SESSION['error'] = $val;
        header('Location: ' . addSession('index.php'));
        return;
    }
    LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate);
Beispiel #3
0
        return;
    }
    LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate);
    // Redirect to ourself
    header('Location: ' . addSession('index.php'));
    return;
}
// echo($goodsha);
if ($LINK->grade > 0) {
    echo '<p class="alert alert-info">Your current grade on this assignment is: ' . $LINK->grade * 100.0 . '%</p>' . "\n";
}
if ($dueDate->message) {
    echo '<p style="color:red;">' . $dueDate->message . '</p>' . "\n";
}
$sample_url = dataUrl('comments_42.html');
$actual_url = dataUrl('comments_' . $code . '.html');
?>
<p>
<b>Scraping Numbers from HTML using BeautifulSoup</b>
In this assignment you will write a Python program similar to 
<a href="http://www.pythonlearn.com/code/urllink2.py" target="_blank">http://www.pythonlearn.com/code/urllink2.py</a>.  
The program will use <b>urllib</b> to read the HTML from the data files below, and parse the data, 
extracting numbers and compute the sum of the numbers in the file.
</p>
<p>
We provide two files for this assignment.  One is a sample file where we give you the sum for your
testing and the other is the actual data you need to process for the assignment.  
<ul>
<li> Sample data: <a href="<?php 
echo deHttps($sample_url);
?>
Beispiel #4
0
        header('Location: ' . addSession('index.php'));
        return;
    }
    LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate);
    // Redirect to ourself
    header('Location: ' . addSession('index.php'));
    return;
}
if ($LINK->grade > 0) {
    echo '<p class="alert alert-info">Your current grade on this assignment is: ' . $LINK->grade * 100.0 . '%</p>' . "\n";
}
if ($dueDate->message) {
    echo '<p style="color:red;">' . $dueDate->message . '</p>' . "\n";
}
$sample_url = dataUrl('known_by_' . $sample_names[0] . '.html');
$actual_url = dataUrl('known_by_' . $actual_names[0] . '.html');
?>
<p>
<b>Following Links in Python</b>
<p>
In this assignment you will write a Python program that expands on
<a href="http://www.pythonlearn.com/code/urllinks.py" target="_blank">http://www.pythonlearn.com/code/urllinks.py</a>.
The program will use <b>urllib</b> to read the HTML from the data files below, 
extract the href= vaues from the anchor tags, scan for a tag that is in 
a particular position relative to the first name in the list,
follow that link and repeat the process
a number of times and report the last name you find.
</p>
<p>
We provide two files for this assignment.  One is a sample file where we give
you the name for your testing and the other is the actual data you need 
Beispiel #5
0
use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Net;
use Tsugi\Util\Mersenne_Twister;
$sanity = array('urllib' => 'You should use urllib to retrieve the data from the API', 'urlencode' => 'You should use urlencode add parameters to the API url', 'json' => 'You should use the json library to parse the API data');
// Compute the stuff for the output
$code = 42;
$MT = new Mersenne_Twister($code);
$sample = $MT->shuffle($LOCATIONS);
$sample_location = $sample[0];
$code = $USER->id + $LINK->id + $CONTEXT->id;
$MT = new Mersenne_Twister($code);
$actual = $MT->shuffle($LOCATIONS);
$actual_location = $actual[0];
// Retrieve the data
$api_url = dataUrl('geojson');
$google_api = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=University+of+Michigan';
$sample_url = $api_url . '?sensor=false&address=' . urlencode($sample_location);
$actual_url = $api_url . '?sensor=false&address=' . urlencode($actual_location);
$sample_data = Net::doGet($sample_url);
$sample_count = strlen($sample_data);
$response = Net::getLastHttpResponse();
$sample_json = json_decode($sample_data);
if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) {
    error_log("DIE: Sample response={$response} url={$sample_url} json_error=" . json_last_error_msg());
    die("Sample response={$response} url={$sample_url} json_error=" . json_last_error_msg());
}
// echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n");
$sample_place = $sample_json->results[0]->place_id;
$actual_data = Net::doGet($actual_url);
$actual_count = strlen($actual_data);