function getReweSearch($suchbegriff) { //$suchbegriff = "milch"; $suchbegriff = preg_replace('/[^a-zA-Z0-9]+/', '', $suchbegriff); //$url = "https://api.import.io/store/connector/478996fb-27a4-45ec-a1d8-2cc119d8d4a2/_query?input=webpage/url:https%3A%2F%2Fshop.rewe.de%2FproductList%3Fsearch%3D" . $suchbegriff . "&&_apikey=40581aa5770c4331b477ca6b191549da6a6ebe6117061cab22ffe286a3bec687a28dd324679b4b65c0e05e44c47739c45a4e56111fd9762d4e3dc345e60732bfe413ad4f56724681aeb33b4055f1e54a"; $url = "https://api.import.io/store/connector/478996fb-27a4-45ec-a1d8-2cc119d8d4a2/_query?input=webpage/url:https%3A%2F%2Fshop.rewe.de%2FproductList%3Fsearch%3D" . $suchbegriff . "%26sorting%3DRELEVANCE%26category%3D%26mobileFiltersOpened%3D%26selectedFacets%3D&&_apikey=40581aa5770c4331b477ca6b191549da6a6ebe6117061cab22ffe286a3bec687a28dd324679b4b65c0e05e44c47739c45a4e56111fd9762d4e3dc345e60732bfe413ad4f56724681aeb33b4055f1e54a"; $result = json_decode(curlData($url), true); //$result = json_decode ( file_get_contents("/Users/raphaelmanke/git/chefkochWrapperToRDF/chefkochWrapperToRDF/library/test.txt"), true ); // print_r($result); foreach ($result["results"] as $resultItem => $resultValue) { foreach ($result["outputProperties"] as $key => $value) { if (isset($result["results"][$resultItem][$value["name"]])) { $formattetArray[$resultItem][preg_replace('/[^a-zA-Z0-9]+/', '-', strtolower($value["name"]))] = $result["results"][$resultItem][$value["name"]]; } } $formattetArray[$resultItem]["identifier"] = "searchResult"; $formattetArray[$resultItem]["suchbegriff"] = $suchbegriff; //$formattetArray [$resultItem] ["wrapperLink"] = "http://wrapper:8888/index.php/reweProdukt/".$formattetArray [$resultItem]["headlineitem-link"]; $formattetArray[$resultItem]["wrapperLink"] = HOST . "index.php/reweProduktWrapper/" . $formattetArray[$resultItem]["headlineitem-link"]; } //print_r($result); // print_r($formattetArray); $graph = new EasyRdf_Graph(); foreach ($formattetArray as $key => $value) { if ($key < 2) { buildTree($graph, $value["headlineitem-link"], $value); } } echo $graph->serialise("turtle"); }
public function getAccessCode() { $appid = $this->appid; $secret = $this->appsecret; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $data = curlData($url); return $data; }
function curlData($url, $params = array(), $type = 'GET', $debug = 0, $options = array()) { $fp = fopen($url, 'wb'); $options = array("CURLOPT_FILE", $fp); $data = curlData($url, $params, $type, $debug, $options); fclose($fp); return $data; }
/** * Sucht auf Rewe nach einem Produkt * @param Integer $produkt * * return Array $value */ function naehrwertSuche($id) { //$query = "https://shop.rewe.de/PD1211326"; $query = "https://shop.rewe.de/PD" . $id; $api_key = "40581aa5770c4331b477ca6b191549da6a6ebe6117061cab22ffe286a3bec687a28dd324679b4b65c0e05e44c47739c45a4e56111fd9762d4e3dc345e60732bfe413ad4f56724681aeb33b4055f1e54a"; $api = "https://api.import.io/store/connector/d1d51bb1-5caf-4369-aa66-026ef8cfd987/_query?input=webpage/url:" . $query . "&&_apikey=" . $api_key; $data = curlData($api); (array) ($value = json_decode($data, True)); // schließe den cURL-Handle und gebe die Systemresourcen frei return $value; }
function fddbSuche($gtin) { //$gtin = "4388844009943"; $gtin = preg_replace('/[^0-9]+/', '', $gtin); $data = curlData("http://fddb.mobi/search/?lang=de&cat=mobile-de&search=" . $gtin); $resultblock = between("<!-- %sresultblock% //-->", "<!-- %eresultblock% //-->", $data); $link = between("window.location.href = '", "';", $data); $area = between("<b>100 g:</b>", "<b>1 Packung:</b>", $data); if ($link != false && strlen($gtin) >= 13) { $werte = array("energy" => preg_replace('/[^0-9,.]+/', '', before("(", $area)), "calories" => preg_replace('/[^0-9,.]+/', '', between("(", ")", $area)), "fat" => preg_replace('/[^0-9,.]+/', '', between("Fett: ", "KH:", $area)), "carbonhydrate" => preg_replace('/[^0-9,.]+/', '', between("KH: ", "<br>", $area))); //$werte = array("Energie", "Energie1", "Fett", "Kohlenhydrate"); $naerhwerte = ""; foreach ($werte as $key => $value) { $naerhwerte[$key]["value"] = preg_replace('/[^0-9]+/', '', $werte[$key]); $naerhwerte[$key]["currencie"] = preg_replace('/[^a-zA-Z]+/', '', $werte[$key]); } $result = array("sourecName" => "fddb", "link" => $link, "gtin" => $gtin, "nutriTable" => $werte, "titel" => between("<a href='" . $link . "'><b>", '</b></a>', $resultblock)); $graph = new EasyRdf_Graph(); $namespace = new EasyRdf_Namespace(); $namespace->set('rezept', "http://manke-hosting.de/ns-syntax#"); buildTree($graph, $result["link"], $result, 'rezept'); echo $graph->serialise("turtle"); } }
function getReweDataByApi($idOrLink, $format) { //$suchbegriff = "milch"; //$suchbegriff = preg_replace ( '/[^a-zA-Z0-9]+/', '', $suchbegriff ); $id = preg_replace('/[^0-9]+/', '', after_last("/PD", $idOrLink)); if ($id == "") { $id = preg_replace('/[^0-9]+/', '', $idOrLink); } $base = "https://shop.rewe.de/PD" . $id; $url = "https://api.import.io/store/connector/d1d51bb1-5caf-4369-aa66-026ef8cfd987/_query?input=webpage/url:" . $base . "&&_apikey=40581aa5770c4331b477ca6b191549da6a6ebe6117061cab22ffe286a3bec687a28dd324679b4b65c0e05e44c47739c45a4e56111fd9762d4e3dc345e60732bfe413ad4f56724681aeb33b4055f1e54a"; $result = json_decode(curlData($url), true); if (empty($result["results"])) { return ""; } //$result = json_decode ( file_get_contents("/Users/raphaelmanke/git/chefkochWrapperToRDF/chefkochWrapperToRDF/library/test.txt"), true ); // print_r($result); foreach ($result["results"] as $resultItem => $resultValue) { $key = str_replace(array('ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü'), array('ae', 'oe', 'ue', 'ss', 'Ae', 'Oe', 'Ue'), $resultValue["naehrwerte"]); $key = preg_replace('/[^a-zA-ZäöüÄÖÜ]+/', '_', $key); $value = preg_replace('/[^0-9,.]+/', '', $resultValue["werte"]); $value = str_replace(".", ",", $value); $currencie = preg_replace('/[^a-zA-Zµ]+/', '', $resultValue["werte"]); if (isset($formattetArray[$resultValue["naehrwerte"]])) { $formattetArray[$key . "1"] = array("value" => $value, "currencie" => $currencie); } else { $formattetArray[$key] = array("value" => $value, "currencie" => $currencie); } //$formattetArray [$resultItem] ["identifier"] = "searchResult"; //$formattetArray [$resultItem] ["suchbegriff"] = $suchbegriff; //$formattetArray [$resultItem] ["wrapperLink"] = "http://wrapper:8888/index.php/reweProdukt/".$formattetArray [$resultItem]["headlineitem-link"]; } $link = str_replace('https:/', 'https://', substr($idOrLink, 0, -1)); $link = str_replace('https:///', 'https://', $link); $array = array("link" => $link, "naehrwerte" => $formattetArray); //print_r($result); //print_r($array); switch ($format) { case "array": return $array; break; case "turtle": return toTurtle($array); break; default: return "falsches Format gewaehlt!"; break; } /* $graph = new EasyRdf_Graph (); foreach ( $formattetArray as $key => $value ) { if ($key < 11) { buildTree ( $graph, $idOrLink, $value ); } } echo $graph->serialise ( "turtle" ); */ }