aboutsummaryrefslogtreecommitdiffstats
path: root/scraper/qwant.php
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2024-10-21 14:16:54 +0000
committerlolcat <will@lolcat.ca>2024-10-21 14:16:54 +0000
commit12d5b4ade817ef9512662e0a65c6850497566a33 (patch)
tree846ee5addac51ed0a87c83b47f436499ffeb9489 /scraper/qwant.php
parentc422abbdc65329e4f3a8eccdeac2a2e560cdff03 (diff)
parent6eabc3edf4a8344e0f508cc1f7f881f5f00dc0fa (diff)
Merge branch 'master' into master
Diffstat (limited to 'scraper/qwant.php')
-rw-r--r--scraper/qwant.php62
1 files changed, 33 insertions, 29 deletions
diff --git a/scraper/qwant.php b/scraper/qwant.php
index 48ecd85..beaa57c 100644
--- a/scraper/qwant.php
+++ b/scraper/qwant.php
@@ -353,26 +353,17 @@ class qwant{
"related" => []
];
- if($json["status"] != "success"){
-
- if($json["data"]["error_code"] === 5){
-
- return $out;
- }
-
- if(isset($json["data"]["error_code"])){
-
- switch($json["data"]["error_code"]){
-
- case 27:
- throw new Exception("Qwant returned a captcha");
- break;
- }
- }
+ if(
+ $json["status"] != "success" &&
+ $json["data"]["error_code"] === 5
+ ){
- throw new Exception("Qwant returned an error code: " . $json["data"]["error_code"]);
+ // no results
+ return $out;
}
+ $this->detect_errors($json);
+
if(!isset($json["data"]["result"]["items"]["mainline"])){
throw new Exception("Server did not return a result object");
@@ -654,10 +645,7 @@ class qwant{
throw new Exception("Failed to decode JSON");
}
- if($json["status"] != "success"){
-
- throw new Exception("Qwant returned an API error");
- }
+ $this->detect_errors($json);
if(isset($json["data"]["result"]["items"]["mainline"])){
@@ -754,10 +742,7 @@ class qwant{
throw new Exception("Could not parse JSON");
}
- if($json["status"] != "success"){
-
- throw new Exception("Qwant returned an API error");
- }
+ $this->detect_errors($json);
if(isset($json["data"]["result"]["items"]["mainline"])){
@@ -861,10 +846,7 @@ class qwant{
throw new Exception("Could not parse JSON");
}
- if($json["status"] != "success"){
-
- throw new Exception("Qwant returned an API error");
- }
+ $this->detect_errors($json);
if(isset($json["data"]["result"]["items"]["mainline"])){
@@ -906,6 +888,28 @@ class qwant{
return $out;
}
+ private function detect_errors($json){
+
+ if(
+ isset($json["status"]) &&
+ $json["status"] == "error"
+ ){
+
+ if(isset($json["data"]["error_data"]["captchaUrl"])){
+
+ throw new Exception("Qwant returned a captcha");
+ }elseif(isset($json["data"]["error_data"]["error_code"])){
+
+ throw new Exception(
+ "Qwant returned an API error: " .
+ $json["data"]["error_data"]["error_code"]
+ );
+ }
+
+ throw new Exception("Qwant returned an API error");
+ }
+ }
+
private function limitstrlen($text){
return explode("\n", wordwrap($text, 300, "\n"))[0];
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage