Open phanirithvij opened 6 years ago
Sounds good. I think completely seperating the results of each search engine and then simply omiting the best guess on Yandex may be a good way to structure the results.
I don't know PHP but I used curl to PHP generator
For the Feature ideas examples on different languages
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:5000/search");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"image_url\":\"http://placehold.it/350x150.png\",
\"resized_images\":true
}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result
?>
I only know basics of go but used a generator
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
// Payload : json struct
type Payload struct {
ImageURL string `json:"image_url"`
ResizedImages bool `json:"resized_images"`
}
func main() {
data := Payload{
// fill struct
ImageURL: "http://placehold.it/350x150.png",
ResizedImages: true,
}
payloadBytes, err := json.Marshal(data)
if err != nil {
// handle err
fmt.Println("error:>", err)
}
body := bytes.NewReader(payloadBytes)
req, err := http.NewRequest("POST", "http://localhost:5000/search", body)
if err != nil {
// handle err
fmt.Println("error:>", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
// handle err
}
if resp.StatusCode == http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)
fmt.Println(bodyString)
}
defer resp.Body.Close()
}
Nothing on ruby either but curl to ruby online
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("http://localhost:5000/search")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request.body = JSON.dump({
"image_url" => "http://placehold.it/350x150.png",
"resized_images" => true
})
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
puts response.code, response.body
Perl by using LWP I don't know Perl either
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "http://localhost:5000/search";
# set custom HTTP request header fields
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('content-type' => 'application/json');
# add POST data to HTTP request body
my $post_data = '{
"image_url": "http://placehold.it/350x150.png",
"resized_images":true
}';
$req->content($post_data);
my $resp = $ua->request($req);
if ($resp->is_success) {
my $message = $resp->decoded_content;
print "Received reply: $message\n";
}
else {
print "HTTP POST error code: ", $resp->code, "\n";
print "HTTP POST error message: ", $resp->message, "\n";
}
Couldn't find a Java code.
@phanirithvij Great! I just commented in the other issue.
I think Yandex is cool. I am suggesting of adding an option to choose between providers (search engines)
But Yandex has no
Best_Guess
Examples
https://www.yandex.com/images/search?text=http%3A%2F%2Fiphones-wallpapers.com%2Fwp-content%2Fuploads%2F2018%2F04%2Fiphone-wallpaper-deadpool-luxury-funny-deadpool-wallpaper-hd-o-oshka-pinterest-of-iphone-wallpaper-deadpool.jpg&img_url=http%3A%2F%2Fiphones-wallpapers.com%2Fwp-content%2Fuploads%2F2018%2F04%2Fiphone-wallpaper-deadpool-luxury-funny-deadpool-wallpaper-hd-o-oshka-pinterest-of-iphone-wallpaper-deadpool.jpg&rpt=imageview
https://www.yandex.com/images/search?text=https%3A//avatars2.githubusercontent.com/u/29627898%3Fs%3D88%26v%3D4&img_url=https%3A//avatars2.githubusercontent.com/u/29627898%3Fs%3D88%26v%3D4&rpt=imageview
Format to search by url of an image
URL_FORMAT
:https://www.yandex.com/images/search?
+text=IMAGE_URL
& +img_url=IMAGE_URL
& +rpt=imageview
Where
IMAGE_URL
is escaped