public function getFBSummary() { $college = str_replace(" ", "", $this->_college); $this->setTitle($college); $url = $this->_baseURL . "/search?q={$this->_titles}&type=page"; $source = urlParser::cURL($url); $decoded = json_decode($source); $id = 0; for ($i = 0; $i < count($decoded->data); $i++) { $val = $decoded->data[$i]->category; if ($val == "education" || $val == "university" || $val == "Education" || $val == "University") { $id = $decoded->data[$i]->id; break; } } $url = $this->_baseURL . "/" . $id; $source = urlParser::cURL($url); $decoded = json_decode($source); $generalInfo = $decoded->general_info; $generalInfo = str_replace("\"", "'", $generalInfo); $generalInfo = str_replace("'", "", $generalInfo); // $address = $decoded->location->street . " " . $decoded->location->city . ", " . $decoded->location->state; $array = array("Summary" => "{$generalInfo}"); $this->_dbConnection->updateTable("CollegeSummary", "CollegeSummary", "CollegeName", $this->_college, "CollegeID", $array, "CollegeName = '{$this->_college}'"); }
public function wikiSnippet() { $college = $this->_college; $college = str_replace(" ", "_", $college); $this->setTitle($college); $this->setProp("revisions"); // section 0 $this->setFormat("php"); $this->setAdditionalProperties("&rvprop=content&rvsection§ion=0"); // text content of page, only the text which appears before $this->setAPIUrl(); $source = urlParser::cURL($this->_apiURL); $decoded = unserialize($source); $key = key($decoded["query"]["pages"]); $valueArray = $decoded["query"]["pages"][$key]["revisions"]["0"]["*"]; // print_r($valueArray); $established = parser::parseSnippet("|established", $valueArray); $established = parser::refineSnippet($established, "established"); //print_r($established); $type = parser::parseSnippet("|type", $valueArray); $type = parser::refineSnippet($type); //print_r($type); $president = parser::parseSnippet("|president", $valueArray); $president = parser::refineSnippet($president); //print_r($president); $city = parser::parseSnippet("|city", $valueArray); $city = parser::refineSnippet($city); //print_r($city); $country = parser::parseSnippet("|country", $valueArray); $country = parser::refineSnippet($country); //print_r($country); $location = $city . ", " . $country; //print_r($location); $endowment = parser::deepParseSnippet("|endowment", $valueArray); $endowment = parser::refineSnippet($endowment); //print_r($endowment); $faculty = parser::parseSnippet("|faculty", $valueArray); $faculty = parser::refineSnippet($faculty, "faculty"); //print_r($faculty); if ($faculty == "") { $faculty = parser::parseSnippet("|staff", $valueArray); // uses $faculty for ease of adding to db $faculty = parser::refineSnippet($faculty, "faculty"); //print_r($athletics); } $undergrad = parser::parseSnippet("|undergrad", $valueArray); if ($undergrad == null) { $undergrad = parser::parseSnippet("| undergrad", $valueArray); } $undergrad = parser::refineSnippet($undergrad, "undergrad"); //print_r($undergrad); $postgrad = parser::parseSnippet("|postgrad", $valueArray); if ($postgrad == null) { $postgrad = parser::parseSnippet("| postgrad", $valueArray); } $postgrad = parser::refineSnippet($postgrad, "postgrad"); if ($postgrad == "") { $postgrad = "0"; } //print_r($postgrad); $campus = parser::parseNew("|campus", $valueArray); $campus = parser::refineSnippet($campus); print_r($campus); return; $athletics = parser::deepParseSnippet("|athletics", $valueArray); $athletics = parser::refineSnippet($athletics); // print_r($athletics); // needs further parsing if ($athletics == "") { $athletics = parser::deepParseSnippet("|free", $valueArray); // used $athletics for ease of adding to db $athletics = parser::refineSnippet($faculty); // print_r($athletics); // needs further parsing } $website = parser::parseSnippet("|website", $valueArray); if ($website == false) { $website = parser::parseSnippet("website", $valueArray); } if ($website == false) { $website = $this->getUrl(); } // print_r($website); $website = parser::refineSnippet($website); // print_r($website); // code to add to database "CollegeSummary" $college = str_replace("_", " ", $this->_college); $array = array("CollegeUrl" => "{$website}", "CollegeLocation" => "{$location}", "CollegePostGrads" => "{$postgrad}", "CollegeUnderGrads" => "{$undergrad}", "CollegeAcademicStaff" => "{$faculty}", "CollegeEndowmentFund" => "{$endowment}", "CollegeCampus" => "{$campus}", "CollegeType" => "{$type}", "CollegeEstablished" => "{$established}", "CollegePresident" => "{$president}"); $this->_dbConnection->updateTable("CollegeSummary", "CollegeSummary", "CollegeName", $college, "CollegeID", $array, "CollegeName = '{$college}'"); }
<?php /** * Tester File for the urlParser.php file. * Provides a log of all the tests run on this class * Should be referenced when debugging a class when something goes wrong. * ########################################### * LOG: ## * This is where the log should be held ## * 07/25: Log Created ## * ## * ########################################### */ // The function __autoload is the method for loading all the classes being used in the script. Use it at the beginning of every php main // page. function __autoload($class) { require_once $class . '.php'; } //Simple test being run //Should excute time tests as well. //It now can take the page and retrieve the URL content; Time to implement the parsing of all links. print_r(urlParser::cURL("http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Harvard_University&rvprop=content&prop=revisions&redirects=1")); echo "hello World";
$baseurl = "http://localhost:8888/CSAPI.php?"; $queryArr = array("Summary", "Research", "Professors", "Pictures", "Majors", "Links", "DivSports", "Clubs", "Arts"); // all possible valid queries $id = "99"; // 1 - 3,000 is a valid range (few numbers above 3,000 will work too) $attribute = "CollegeName"; $formatArr = array("php", "json"); $query = $queryArr[0]; //$id = "99"; // 1 - 3,000 is a valid range (few numbers above 3,000 will work too) $attribute = "CollegeName"; $format = $formatArr[0]; $url = $baseurl . "query=" . $query . "&id=" . $id . "&format=" . $format; // query and id MUST be specified if (!empty($attribute)) { // attribute parameter is optional $url = $url . "&attribute=" . $attribute; } //cURLs the api url to get page contents (output of api call) $source = urlParser::cURL($url); $decoded; if ($format = "php") { $decoded = unserialize($source); } if ($format = "json") { $decoded = json_decode($source); } //print_r($decoded[0]); $stringToWrite = "\n"; $stream = fopen("/csapitestoutput.txt", "x+"); fwrite($stream, $stringToWrite); fclose($stream);