Например 50
bing.index

Реализация на языке java

Java[11] — объектно-ориентированный язык программирования, разработанный компанией Sun Microsystems (в последующем приобретённой компанией Oracle). Приложения Java обычно транслируются в специальный байт-код, поэтому они могут работать на любой виртуальной Java-машине вне зависимости от компьютерной архитектуры. Дата официального выпуска — 23 мая 1995 года.

Особенности запуска

Для постановки в очередь:

сохраните файл Request.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/Request.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.Request

Для получения данных:

сохраните файл GetData.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/GetData.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.GetData

Постановка задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package io.smartfetch;

import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------  Описание запроса
class DataObject {
    public List<String> column = new ArrayList<String>() {
        {
            
        }
    };

    public List<List<String>> data = new ArrayList<List<String>>();

    public DataObject()
    {

        data.add(new ArrayList<String>(){
            {
                
            }
        });

        data.add(new ArrayList<String>(){
            {
                
            }
        });
        data.add(new ArrayList<String>(){
            {
                
            }
        });
    }
}
//---------------------------------------------------------

//------------------------------ Описание ответа

class ResponseObject {
    public String success;
    public int duration;
    public String backgroundColor;
    public String message;
    public String hash;
}
//------------------------------------------------------

class Post {

    private String _key;

    public Post(String key) {
        _key = key;
    }

    // Возвращает JSON с параметрами запроса
    private String FormatJson() {
        DataObject obj = new DataObject();
        Gson gson = new Gson();

        String json = gson.toJson(obj);

        return json;
    }

    // Выполняет запрос к серверу и возвращает ответ
    private HttpResponse MakeRequest(String json) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            HttpPost post = new HttpPost(new URI("http", "smartfetch.io", "/" + _key + "/api/", null, null));

            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("task", "bingindex"));
            params.add(new BasicNameValuePair("data", json));
            post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //post.

            response = httpClient.execute(post);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            httpClient.getConnectionManager().shutdown();
        }

        return response;
    }

    public void Run() throws IOException {
        String json = FormatJson(); // Формирование запроса

        HttpResponse response = MakeRequest(json); // Запрос

        if (response == null) {
            System.out.print("Ошибка при отправке запроса");
            return;
        }

        // Разбор ответа
        if (response.getStatusLine().getStatusCode() == 200) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            Gson gson = new Gson();

            ResponseObject result = gson.fromJson(responseString, ResponseObject.class);

            if (result.success == "true") {
                System.out.println("ok " + result.hash);
            } else {
                if (result.message != null) {
                    System.out.println("error " + result.message);
                } else {
                    System.out.println("error");
                }
            }
        }
    }
}

public class Request {

    public static void main(String[] args) throws IOException {
	    Post pst = new Post("API КЛЮЧ");
        pst.Run();
    }
}
Получение задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package io.smartfetch;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

class Get {
    private String _key;
    private String _hash;
    private String FileName = "temp";

    public Get(String key, String hash) { _key = key; _hash = hash; }

    // Удаляем всю временную информацию
    private void clearTempData() throws IOException {
        File archive = new File(FileName + ".zip");
        if (archive.exists())
            archive.delete();

        File directory = new File(FileName);

        FileUtils.deleteDirectory(directory);
    }

    // Загружаем файл
    public void downloadZipFile() {
        String saveTo = FileName + ".zip";
        try {
            URL url = new URL("http://smartfetch.io/" + _key + "/get/"+ _hash);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
            FileOutputStream out = new FileOutputStream(saveTo);
            byte[] b = new byte[1024];
            int count;
            while ((count = in.read(b)) >= 0) {
                out.write(b, 0, count);
            }
            out.flush(); out.close(); in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Разархивируем полученные данные
    public void unZip() throws IOException {

        byte[] buffer = new byte[1024];

        File folder = new File(FileName);
        if(!folder.exists()){
            folder.mkdir();
        }

        ZipInputStream zis =
                new ZipInputStream(new FileInputStream(FileName + ".zip"));
        ZipEntry ze = zis.getNextEntry();

        while(ze!=null){

            String fileName = ze.getName();
            File newFile = new File(FileName + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();
            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    }

    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public void Run() throws IOException {
        clearTempData();
        downloadZipFile();
        unZip();

        File directory = new File(FileName);

        String[] items = directory.list();
        String[] columns = readFile(FileName + "/column.txt", Charset.defaultCharset()).split(",");

        for (String item : items) {
            if (!item.endsWith(".json"))
                continue;

            Map<String, Object> data; // parse
            Gson gson = new Gson();
            data = gson.fromJson("{ 'data' :" + readFile(FileName + "/" + item, Charset.defaultCharset()) + "}", Map.class);

            // В поле data в двумерном массиве содержаться результаты
            JsonObject answer = (JsonObject) gson.toJsonTree(data);
        }

        clearTempData();
    }
}

public class Get {

    public static void main(String[] args) throws IOException {
        Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

        gt.Run();
    }
}
Особенности запуска

Для постановки в очередь:

сохраните файл Request.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/Request.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.Request

Для получения данных:

сохраните файл GetData.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/GetData.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.GetData

Постановка задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package io.smartfetch;

import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------  Описание запроса
class DataObject {
    public List<String> column = new ArrayList<String>() {
        {
            
        }
    };

    public List<List<String>> data = new ArrayList<List<String>>();

    public DataObject()
    {

        data.add(new ArrayList<String>(){
            {
                
            }
        });

        data.add(new ArrayList<String>(){
            {
                
            }
        });
        data.add(new ArrayList<String>(){
            {
                
            }
        });
    }
}
//---------------------------------------------------------

//------------------------------ Описание ответа

class ResponseObject {
    public String success;
    public int duration;
    public String backgroundColor;
    public String message;
    public String hash;
}
//------------------------------------------------------

class Post {

    private String _key;

    public Post(String key) {
        _key = key;
    }

    // Возвращает JSON с параметрами запроса
    private String FormatJson() {
        DataObject obj = new DataObject();
        Gson gson = new Gson();

        String json = gson.toJson(obj);

        return json;
    }

    // Выполняет запрос к серверу и возвращает ответ
    private HttpResponse MakeRequest(String json) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            HttpPost post = new HttpPost(new URI("http", "smartfetch.io", "/" + _key + "/api/", null, null));

            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("task", "bingindex"));
            params.add(new BasicNameValuePair("data", json));
            post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //post.

            response = httpClient.execute(post);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            httpClient.getConnectionManager().shutdown();
        }

        return response;
    }

    public void Run() throws IOException {
        String json = FormatJson(); // Формирование запроса

        HttpResponse response = MakeRequest(json); // Запрос

        if (response == null) {
            System.out.print("Ошибка при отправке запроса");
            return;
        }

        // Разбор ответа
        if (response.getStatusLine().getStatusCode() == 200) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            Gson gson = new Gson();

            ResponseObject result = gson.fromJson(responseString, ResponseObject.class);

            if (result.success == "true") {
                System.out.println("ok " + result.hash);
            } else {
                if (result.message != null) {
                    System.out.println("error " + result.message);
                } else {
                    System.out.println("error");
                }
            }
        }
    }
}

public class Request {

    public static void main(String[] args) throws IOException {
	    Post pst = new Post("API КЛЮЧ");
        pst.Run();
    }
}
Получение задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package io.smartfetch;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

class Get {
    private String _key;
    private String _hash;
    private String FileName = "temp";

    public Get(String key, String hash) { _key = key; _hash = hash; }

    // Удаляем всю временную информацию
    private void clearTempData() throws IOException {
        File archive = new File(FileName + ".zip");
        if (archive.exists())
            archive.delete();

        File directory = new File(FileName);

        FileUtils.deleteDirectory(directory);
    }

    // Загружаем файл
    public void downloadZipFile() {
        String saveTo = FileName + ".zip";
        try {
            URL url = new URL("http://smartfetch.io/" + _key + "/get/"+ _hash);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
            FileOutputStream out = new FileOutputStream(saveTo);
            byte[] b = new byte[1024];
            int count;
            while ((count = in.read(b)) >= 0) {
                out.write(b, 0, count);
            }
            out.flush(); out.close(); in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Разархивируем полученные данные
    public void unZip() throws IOException {

        byte[] buffer = new byte[1024];

        File folder = new File(FileName);
        if(!folder.exists()){
            folder.mkdir();
        }

        ZipInputStream zis =
                new ZipInputStream(new FileInputStream(FileName + ".zip"));
        ZipEntry ze = zis.getNextEntry();

        while(ze!=null){

            String fileName = ze.getName();
            File newFile = new File(FileName + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();
            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    }

    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public void Run() throws IOException {
        clearTempData();
        downloadZipFile();
        unZip();

        File directory = new File(FileName);

        String[] items = directory.list();
        String[] columns = readFile(FileName + "/column.txt", Charset.defaultCharset()).split(",");

        for (String item : items) {
            if (!item.endsWith(".json"))
                continue;

            Map<String, Object> data; // parse
            Gson gson = new Gson();
            data = gson.fromJson("{ 'data' :" + readFile(FileName + "/" + item, Charset.defaultCharset()) + "}", Map.class);

            // В поле data в двумерном массиве содержаться результаты
            JsonObject answer = (JsonObject) gson.toJsonTree(data);
        }

        clearTempData();
    }
}

public class Get {

    public static void main(String[] args) throws IOException {
        Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

        gt.Run();
    }
}
Особенности запуска

Для постановки в очередь:

сохраните файл Request.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/Request.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.Request

Для получения данных:

сохраните файл GetData.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/GetData.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.GetData

Постановка задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package io.smartfetch;

import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------  Описание запроса
class DataObject {
    public List<String> column = new ArrayList<String>() {
        {
            
        }
    };

    public List<List<String>> data = new ArrayList<List<String>>();

    public DataObject()
    {

        data.add(new ArrayList<String>(){
            {
                
            }
        });

        data.add(new ArrayList<String>(){
            {
                
            }
        });
        data.add(new ArrayList<String>(){
            {
                
            }
        });
    }
}
//---------------------------------------------------------

//------------------------------ Описание ответа

class ResponseObject {
    public String success;
    public int duration;
    public String backgroundColor;
    public String message;
    public String hash;
}
//------------------------------------------------------

class Post {

    private String _key;

    public Post(String key) {
        _key = key;
    }

    // Возвращает JSON с параметрами запроса
    private String FormatJson() {
        DataObject obj = new DataObject();
        Gson gson = new Gson();

        String json = gson.toJson(obj);

        return json;
    }

    // Выполняет запрос к серверу и возвращает ответ
    private HttpResponse MakeRequest(String json) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            HttpPost post = new HttpPost(new URI("http", "smartfetch.io", "/" + _key + "/api/", null, null));

            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("task", "bingindex"));
            params.add(new BasicNameValuePair("data", json));
            post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //post.

            response = httpClient.execute(post);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            httpClient.getConnectionManager().shutdown();
        }

        return response;
    }

    public void Run() throws IOException {
        String json = FormatJson(); // Формирование запроса

        HttpResponse response = MakeRequest(json); // Запрос

        if (response == null) {
            System.out.print("Ошибка при отправке запроса");
            return;
        }

        // Разбор ответа
        if (response.getStatusLine().getStatusCode() == 200) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            Gson gson = new Gson();

            ResponseObject result = gson.fromJson(responseString, ResponseObject.class);

            if (result.success == "true") {
                System.out.println("ok " + result.hash);
            } else {
                if (result.message != null) {
                    System.out.println("error " + result.message);
                } else {
                    System.out.println("error");
                }
            }
        }
    }
}

public class Request {

    public static void main(String[] args) throws IOException {
	    Post pst = new Post("API КЛЮЧ");
        pst.Run();
    }
}
Получение задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package io.smartfetch;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

class Get {
    private String _key;
    private String _hash;
    private String FileName = "temp";

    public Get(String key, String hash) { _key = key; _hash = hash; }

    // Удаляем всю временную информацию
    private void clearTempData() throws IOException {
        File archive = new File(FileName + ".zip");
        if (archive.exists())
            archive.delete();

        File directory = new File(FileName);

        FileUtils.deleteDirectory(directory);
    }

    // Загружаем файл
    public void downloadZipFile() {
        String saveTo = FileName + ".zip";
        try {
            URL url = new URL("http://smartfetch.io/" + _key + "/get/"+ _hash);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
            FileOutputStream out = new FileOutputStream(saveTo);
            byte[] b = new byte[1024];
            int count;
            while ((count = in.read(b)) >= 0) {
                out.write(b, 0, count);
            }
            out.flush(); out.close(); in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Разархивируем полученные данные
    public void unZip() throws IOException {

        byte[] buffer = new byte[1024];

        File folder = new File(FileName);
        if(!folder.exists()){
            folder.mkdir();
        }

        ZipInputStream zis =
                new ZipInputStream(new FileInputStream(FileName + ".zip"));
        ZipEntry ze = zis.getNextEntry();

        while(ze!=null){

            String fileName = ze.getName();
            File newFile = new File(FileName + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();
            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    }

    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public void Run() throws IOException {
        clearTempData();
        downloadZipFile();
        unZip();

        File directory = new File(FileName);

        String[] items = directory.list();
        String[] columns = readFile(FileName + "/column.txt", Charset.defaultCharset()).split(",");

        for (String item : items) {
            if (!item.endsWith(".json"))
                continue;

            Map<String, Object> data; // parse
            Gson gson = new Gson();
            data = gson.fromJson("{ 'data' :" + readFile(FileName + "/" + item, Charset.defaultCharset()) + "}", Map.class);

            // В поле data в двумерном массиве содержаться результаты
            JsonObject answer = (JsonObject) gson.toJsonTree(data);
        }

        clearTempData();
    }
}

public class Get {

    public static void main(String[] args) throws IOException {
        Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

        gt.Run();
    }
}
Особенности запуска

Для постановки в очередь:

сохраните файл Request.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/Request.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.Request

Для получения данных:

сохраните файл GetData.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/GetData.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.GetData

Постановка задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package io.smartfetch;

import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------  Описание запроса
class DataObject {
    public List<String> column = new ArrayList<String>() {
        {
            
        }
    };

    public List<List<String>> data = new ArrayList<List<String>>();

    public DataObject()
    {

        data.add(new ArrayList<String>(){
            {
                
            }
        });

        data.add(new ArrayList<String>(){
            {
                
            }
        });
        data.add(new ArrayList<String>(){
            {
                
            }
        });
    }
}
//---------------------------------------------------------

//------------------------------ Описание ответа

class ResponseObject {
    public String success;
    public int duration;
    public String backgroundColor;
    public String message;
    public String hash;
}
//------------------------------------------------------

class Post {

    private String _key;

    public Post(String key) {
        _key = key;
    }

    // Возвращает JSON с параметрами запроса
    private String FormatJson() {
        DataObject obj = new DataObject();
        Gson gson = new Gson();

        String json = gson.toJson(obj);

        return json;
    }

    // Выполняет запрос к серверу и возвращает ответ
    private HttpResponse MakeRequest(String json) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            HttpPost post = new HttpPost(new URI("http", "smartfetch.io", "/" + _key + "/api/", null, null));

            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("task", "bingindex"));
            params.add(new BasicNameValuePair("data", json));
            post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //post.

            response = httpClient.execute(post);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            httpClient.getConnectionManager().shutdown();
        }

        return response;
    }

    public void Run() throws IOException {
        String json = FormatJson(); // Формирование запроса

        HttpResponse response = MakeRequest(json); // Запрос

        if (response == null) {
            System.out.print("Ошибка при отправке запроса");
            return;
        }

        // Разбор ответа
        if (response.getStatusLine().getStatusCode() == 200) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            Gson gson = new Gson();

            ResponseObject result = gson.fromJson(responseString, ResponseObject.class);

            if (result.success == "true") {
                System.out.println("ok " + result.hash);
            } else {
                if (result.message != null) {
                    System.out.println("error " + result.message);
                } else {
                    System.out.println("error");
                }
            }
        }
    }
}

public class Request {

    public static void main(String[] args) throws IOException {
	    Post pst = new Post("API КЛЮЧ");
        pst.Run();
    }
}
Получение задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package io.smartfetch;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

class Get {
    private String _key;
    private String _hash;
    private String FileName = "temp";

    public Get(String key, String hash) { _key = key; _hash = hash; }

    // Удаляем всю временную информацию
    private void clearTempData() throws IOException {
        File archive = new File(FileName + ".zip");
        if (archive.exists())
            archive.delete();

        File directory = new File(FileName);

        FileUtils.deleteDirectory(directory);
    }

    // Загружаем файл
    public void downloadZipFile() {
        String saveTo = FileName + ".zip";
        try {
            URL url = new URL("http://smartfetch.io/" + _key + "/get/"+ _hash);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
            FileOutputStream out = new FileOutputStream(saveTo);
            byte[] b = new byte[1024];
            int count;
            while ((count = in.read(b)) >= 0) {
                out.write(b, 0, count);
            }
            out.flush(); out.close(); in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Разархивируем полученные данные
    public void unZip() throws IOException {

        byte[] buffer = new byte[1024];

        File folder = new File(FileName);
        if(!folder.exists()){
            folder.mkdir();
        }

        ZipInputStream zis =
                new ZipInputStream(new FileInputStream(FileName + ".zip"));
        ZipEntry ze = zis.getNextEntry();

        while(ze!=null){

            String fileName = ze.getName();
            File newFile = new File(FileName + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();
            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    }

    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public void Run() throws IOException {
        clearTempData();
        downloadZipFile();
        unZip();

        File directory = new File(FileName);

        String[] items = directory.list();
        String[] columns = readFile(FileName + "/column.txt", Charset.defaultCharset()).split(",");

        for (String item : items) {
            if (!item.endsWith(".json"))
                continue;

            Map<String, Object> data; // parse
            Gson gson = new Gson();
            data = gson.fromJson("{ 'data' :" + readFile(FileName + "/" + item, Charset.defaultCharset()) + "}", Map.class);

            // В поле data в двумерном массиве содержаться результаты
            JsonObject answer = (JsonObject) gson.toJsonTree(data);
        }

        clearTempData();
    }
}

public class Get {

    public static void main(String[] args) throws IOException {
        Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

        gt.Run();
    }
}
Особенности запуска

Для постановки в очередь:

сохраните файл Request.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/Request.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.Request

Для получения данных:

сохраните файл GetData.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/GetData.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.GetData

Постановка задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package io.smartfetch;

import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------  Описание запроса
class DataObject {
    public List<String> column = new ArrayList<String>() {
        {
            
        }
    };

    public List<List<String>> data = new ArrayList<List<String>>();

    public DataObject()
    {

        data.add(new ArrayList<String>(){
            {
                
            }
        });

        data.add(new ArrayList<String>(){
            {
                
            }
        });
        data.add(new ArrayList<String>(){
            {
                
            }
        });
    }
}
//---------------------------------------------------------

//------------------------------ Описание ответа

class ResponseObject {
    public String success;
    public int duration;
    public String backgroundColor;
    public String message;
    public String hash;
}
//------------------------------------------------------

class Post {

    private String _key;

    public Post(String key) {
        _key = key;
    }

    // Возвращает JSON с параметрами запроса
    private String FormatJson() {
        DataObject obj = new DataObject();
        Gson gson = new Gson();

        String json = gson.toJson(obj);

        return json;
    }

    // Выполняет запрос к серверу и возвращает ответ
    private HttpResponse MakeRequest(String json) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            HttpPost post = new HttpPost(new URI("http", "smartfetch.io", "/" + _key + "/api/", null, null));

            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("task", "bingindex"));
            params.add(new BasicNameValuePair("data", json));
            post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //post.

            response = httpClient.execute(post);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            httpClient.getConnectionManager().shutdown();
        }

        return response;
    }

    public void Run() throws IOException {
        String json = FormatJson(); // Формирование запроса

        HttpResponse response = MakeRequest(json); // Запрос

        if (response == null) {
            System.out.print("Ошибка при отправке запроса");
            return;
        }

        // Разбор ответа
        if (response.getStatusLine().getStatusCode() == 200) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            Gson gson = new Gson();

            ResponseObject result = gson.fromJson(responseString, ResponseObject.class);

            if (result.success == "true") {
                System.out.println("ok " + result.hash);
            } else {
                if (result.message != null) {
                    System.out.println("error " + result.message);
                } else {
                    System.out.println("error");
                }
            }
        }
    }
}

public class Request {

    public static void main(String[] args) throws IOException {
	    Post pst = new Post("API КЛЮЧ");
        pst.Run();
    }
}
Получение задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package io.smartfetch;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

class Get {
    private String _key;
    private String _hash;
    private String FileName = "temp";

    public Get(String key, String hash) { _key = key; _hash = hash; }

    // Удаляем всю временную информацию
    private void clearTempData() throws IOException {
        File archive = new File(FileName + ".zip");
        if (archive.exists())
            archive.delete();

        File directory = new File(FileName);

        FileUtils.deleteDirectory(directory);
    }

    // Загружаем файл
    public void downloadZipFile() {
        String saveTo = FileName + ".zip";
        try {
            URL url = new URL("http://smartfetch.io/" + _key + "/get/"+ _hash);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
            FileOutputStream out = new FileOutputStream(saveTo);
            byte[] b = new byte[1024];
            int count;
            while ((count = in.read(b)) >= 0) {
                out.write(b, 0, count);
            }
            out.flush(); out.close(); in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Разархивируем полученные данные
    public void unZip() throws IOException {

        byte[] buffer = new byte[1024];

        File folder = new File(FileName);
        if(!folder.exists()){
            folder.mkdir();
        }

        ZipInputStream zis =
                new ZipInputStream(new FileInputStream(FileName + ".zip"));
        ZipEntry ze = zis.getNextEntry();

        while(ze!=null){

            String fileName = ze.getName();
            File newFile = new File(FileName + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();
            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    }

    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public void Run() throws IOException {
        clearTempData();
        downloadZipFile();
        unZip();

        File directory = new File(FileName);

        String[] items = directory.list();
        String[] columns = readFile(FileName + "/column.txt", Charset.defaultCharset()).split(",");

        for (String item : items) {
            if (!item.endsWith(".json"))
                continue;

            Map<String, Object> data; // parse
            Gson gson = new Gson();
            data = gson.fromJson("{ 'data' :" + readFile(FileName + "/" + item, Charset.defaultCharset()) + "}", Map.class);

            // В поле data в двумерном массиве содержаться результаты
            JsonObject answer = (JsonObject) gson.toJsonTree(data);
        }

        clearTempData();
    }
}

public class Get {

    public static void main(String[] args) throws IOException {
        Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

        gt.Run();
    }
}
Особенности запуска

Для постановки в очередь:

сохраните файл Request.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/Request.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.Request

Для получения данных:

сохраните файл GetData.java в папку ru/smartfetch

Компилируем:

javac  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru/smartfetch/GetData.java

Запускаем:

java  -classpath ".:httpclient-4.0.jar:httpcore-4.0.1.jar:gson-2.3.1.jar:apacheds-all-1.5.4.jar:commons-logging-1.2.jar"  ru.smartfetch.GetData

Постановка задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package io.smartfetch;

import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------  Описание запроса
class DataObject {
    public List<String> column = new ArrayList<String>() {
        {
            
        }
    };

    public List<List<String>> data = new ArrayList<List<String>>();

    public DataObject()
    {

        data.add(new ArrayList<String>(){
            {
                
            }
        });

        data.add(new ArrayList<String>(){
            {
                
            }
        });
        data.add(new ArrayList<String>(){
            {
                
            }
        });
    }
}
//---------------------------------------------------------

//------------------------------ Описание ответа

class ResponseObject {
    public String success;
    public int duration;
    public String backgroundColor;
    public String message;
    public String hash;
}
//------------------------------------------------------

class Post {

    private String _key;

    public Post(String key) {
        _key = key;
    }

    // Возвращает JSON с параметрами запроса
    private String FormatJson() {
        DataObject obj = new DataObject();
        Gson gson = new Gson();

        String json = gson.toJson(obj);

        return json;
    }

    // Выполняет запрос к серверу и возвращает ответ
    private HttpResponse MakeRequest(String json) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            HttpPost post = new HttpPost(new URI("http", "smartfetch.io", "/" + _key + "/api/", null, null));

            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("task", "bingindex"));
            params.add(new BasicNameValuePair("data", json));
            post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            //post.

            response = httpClient.execute(post);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            httpClient.getConnectionManager().shutdown();
        }

        return response;
    }

    public void Run() throws IOException {
        String json = FormatJson(); // Формирование запроса

        HttpResponse response = MakeRequest(json); // Запрос

        if (response == null) {
            System.out.print("Ошибка при отправке запроса");
            return;
        }

        // Разбор ответа
        if (response.getStatusLine().getStatusCode() == 200) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            Gson gson = new Gson();

            ResponseObject result = gson.fromJson(responseString, ResponseObject.class);

            if (result.success == "true") {
                System.out.println("ok " + result.hash);
            } else {
                if (result.message != null) {
                    System.out.println("error " + result.message);
                } else {
                    System.out.println("error");
                }
            }
        }
    }
}

public class Request {

    public static void main(String[] args) throws IOException {
	    Post pst = new Post("API КЛЮЧ");
        pst.Run();
    }
}
Получение задания
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package io.smartfetch;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

class Get {
    private String _key;
    private String _hash;
    private String FileName = "temp";

    public Get(String key, String hash) { _key = key; _hash = hash; }

    // Удаляем всю временную информацию
    private void clearTempData() throws IOException {
        File archive = new File(FileName + ".zip");
        if (archive.exists())
            archive.delete();

        File directory = new File(FileName);

        FileUtils.deleteDirectory(directory);
    }

    // Загружаем файл
    public void downloadZipFile() {
        String saveTo = FileName + ".zip";
        try {
            URL url = new URL("http://smartfetch.io/" + _key + "/get/"+ _hash);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
            FileOutputStream out = new FileOutputStream(saveTo);
            byte[] b = new byte[1024];
            int count;
            while ((count = in.read(b)) >= 0) {
                out.write(b, 0, count);
            }
            out.flush(); out.close(); in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Разархивируем полученные данные
    public void unZip() throws IOException {

        byte[] buffer = new byte[1024];

        File folder = new File(FileName);
        if(!folder.exists()){
            folder.mkdir();
        }

        ZipInputStream zis =
                new ZipInputStream(new FileInputStream(FileName + ".zip"));
        ZipEntry ze = zis.getNextEntry();

        while(ze!=null){

            String fileName = ze.getName();
            File newFile = new File(FileName + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();
            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    }

    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public void Run() throws IOException {
        clearTempData();
        downloadZipFile();
        unZip();

        File directory = new File(FileName);

        String[] items = directory.list();
        String[] columns = readFile(FileName + "/column.txt", Charset.defaultCharset()).split(",");

        for (String item : items) {
            if (!item.endsWith(".json"))
                continue;

            Map<String, Object> data; // parse
            Gson gson = new Gson();
            data = gson.fromJson("{ 'data' :" + readFile(FileName + "/" + item, Charset.defaultCharset()) + "}", Map.class);

            // В поле data в двумерном массиве содержаться результаты
            JsonObject answer = (JsonObject) gson.toJsonTree(data);
        }

        clearTempData();
    }
}

public class Get {

    public static void main(String[] args) throws IOException {
        Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

        gt.Run();
    }
}