Ejemplo n.º 1
0
function shouldScrapeByTerm($term)
{
    $cc = new cURL();
    $output = $cc->get('http://www.nyu.edu/registrar/listings/');
    $output = substring($output, 'Course data was last updated on ', '<form method="post" name="selForm" action="results.html">', true);
    $date = substr($output, 0, strlen($output) - 5);
    $scrapeDate = date('Y-m-d H:i:s', strtotime($date));
    $sql = 'SELECT * FROM `nyu_courses_settings`';
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    if (!(stripos($term, "Fall") === false)) {
        $column = "latest_fall_scrape";
    } else {
        if (!(stripos($term, "Spring") === false)) {
            $column = "latest_spring_scrape";
        } else {
            if (!(stripos($term, "Winter") === false)) {
                $column = "latest_ws_scrape";
            } else {
                if (!(stripos($term, "Summer") === false)) {
                    $column = "latest_ws_scrape";
                }
            }
        }
    }
    if ($row[$column] != $scrapeDate) {
        scrape($term, $scrapeDate);
        deleteOldData($term, $scrapeDate);
        $sql = "UPDATE `nyu_courses_settings` SET `{$column}` = '{$scrapeDate}'";
        mysql_query($sql);
    }
}
    $totalMonth = 0;
    $i = 0;
    $time = "";
    $tiemstamp = "";
    foreach ($result as $value) {
        $totalMonth = $totalMonth + $value['total'];
        if ($i == 0) {
            $time = $value['date'];
            $timestamp = $value['unix_time'];
        }
        $i++;
    }
    storeInDatabase($time, $timestamp, $totalMonth, 2);
    deleteOldData($timestamp, 0);
    $timestamp = $timestamp - 380 * 24 * 60 * 60;
    deleteOldData($timestamp, 2);
}
function deleteOldData($unix_time, $type)
{
    global $pDB;
    $query = "delete from email_statistics where unix_time < ? and type=?";
    $result = $pDB->genQuery($query, array($unix_time, $type));
    if ($result == FALSE) {
        wlog($pDB->errMsg . "\n");
    }
}
function getDataDaysBefore($unix_time)
{
    global $pDB;
    $day = date('d', $unix_time);
    if ($day == "28") {