/**
 * procc the request
 */
function proc_args()
{
    global $args;
    switch ($args[0]) {
        case 'run_scrape':
            $MV_BillScraper = new MV_BillScraper();
            $MV_BillScraper->procArguments();
            $MV_BillScraper->doScrapeInsert();
            break;
        default:
            usage();
            break;
    }
}
function do_proc_interest($intrestKey, $intrestName)
{
    global $mvMaxContribPerInterest, $mvMaxForAgainstBills;
    include_once 'scrape_and_insert.inc.php';
    $mvScrape = new MV_BillScraper();
    $raw_results = $mvScrape->doRequest('http://www.maplight.org/map/us/interest/' . $intrestKey . '/view/all');
    $page_body = '{{Interest Group|' . "\n";
    $page_body .= 'MAPLight Interest ID=' . $intrestKey . "|\n";
    // get all people contributions:
    preg_match_all('/\\/map\\/us\\/legislator\\/([^"]*)">.*\\$([^<]*)</U', $raw_results, $matches);
    if (isset($matches[2])) {
        $i = 0;
        foreach ($matches[1] as $i => $person_id) {
            $hr_inx = $i + 1;
            // we have to lookup the name:
            $personName = $mvScrape->get_wiki_name_from_maplightid($person_id);
            if ($personName) {
                $page_body .= "Funded Name {$hr_inx}=" . $personName . "|\n";
                $page_body .= "Funded Amount {$hr_inx}=" . str_replace(',', '', $matches[2][$i]) . "|\n";
            }
            if ($hr_inx == $mvMaxContribPerInterest) {
                break;
            }
            $i++;
        }
    }
    $intrest_bills_url = 'http://maplight.org/map/us/interest/' . $intrestKey . '/bills';
    $raw_results = $mvScrape->doRequest($intrest_bills_url);
    // get all bills supported or opposed
    preg_match_all('/\\/map\\/us\\/bill\\/([^"]*)".*\\/map\\/us\\/legislator.*<td>([^<]*)</U', $raw_results, $matches);
    print 'bill:' . $intrest_bills_url . "\n";
    //die;
    $sinx = $oinx = 1;
    if (isset($matches[1][0])) {
        $support_count = $oppse_count = 0;
        foreach ($matches[1] as $i => $bill_id) {
            // skip if we are maxed out
            if ($support_count == $mvMaxForAgainstBills) {
                continue;
            }
            if ($oppse_count == $mvMaxForAgainstBills) {
                continue;
            }
            $hr_inx = $i + 1;
            $bill_name = $mvScrape->get_bill_name_from_mapLight_id($bill_id);
            if ($matches[2][$i] == 'Support') {
                $page_body .= "Supported Bill {$sinx}=" . str_replace('_', ' ', $bill_name) . "|\n";
                $sinx++;
            } elseif ($matches[2][$i] == 'Oppose') {
                $page_body .= "Opposed Bill {$oinx}=" . str_replace('_', ' ', $bill_name) . "|\n";
                $oinx++;
            }
        }
    }
    $page_body .= '}}';
    $wTitle = Title::makeTitle(NS_MAIN, $intrestName);
    print "Interest: ";
    do_update_wiki_page($wTitle, $page_body);
    print "\n";
}