Например парсер авито
bing.index

Реализация на языке C#

ASP (англ. Active Server Pages — «активные серверные страницы») — технология, предложенная компанией Microsoft в 1996 году для создания Web-приложений. Эта технология основана на внедрении в обыкновенные веб-страницы специальных элементов управления, допускающих программное управление.

Постановка задания
  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
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Post
    {
        // -----------------    Описание запроса
        [DataContract]
        public class Data
        {
            [DataMember(Name = "column")]
            public string[] Column { get; set; }
            [DataMember(Name = "data")]
            public string[][] SData { get; set; }
        }
        // -----------------------

        //----------------------  Описание ответа
        [DataContract]
        public class Response
        {
            [DataMember(Name = "success")]
            public bool Success { get; set; }
            [DataMember(Name = "duration")]
            public Int32 Duration { get; set; }
            [DataMember(Name = "backgroundColor")]
            public string BackgroundColor { get; set; }
            [DataMember(Name = "message")]
            public string Message { get; set; }
            [DataMember(Name = "hash")]
            public string Hash { get; set; }
        }
        // ---------------------------------

        private string _key = "[API_KEY]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/

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

        // Формируем запрос
        private string FormatJson()
        {
            // Создание объекста, содержащего все параметры запроса
            var data = new Data()
            {
                
                SData = new[]
                {
                    new[] {   },
                    new[] {   },
                    new[] {   }
                }

            };

            // Формируем JSON из объекта
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));

            ser.WriteObject(stream1, data);

            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            string json = sr.ReadToEnd();

            return json;
        }

        // Выполняем запрос к серверу
        private string MakeRequest(string data)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://smartfetch.io/{0}/api/", _key));

            string postData = "task=bingindex";
            postData += "&data=" + data;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(postData);
                streamWriter.Flush();
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
        }

        // Разбирает ответ от сервера
        private Response ParseResponse(string json)
        {
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(json));

            return (Response)js.ReadObject(ms);
        }

        public void Run()
        {
            string request = FormatJson();

            string response = MakeRequest(request);

            Response res = ParseResponse(response);

            if (res.Success)
            {
                Console.WriteLine(String.Format("ok {0}", res.Hash));
            }
            else
            {
                if (res.Message != null)
                    Console.WriteLine(string.Format("error {0}", res.Message));
                else
                    Console.WriteLine("error");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Post pt = new Post("");
            pt.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Get
    {
        // ------------ Описание формата ответа
        [DataContract]
        class Response
        {
            [DataMember(Name = "data")]
            public List<List<String>> Data { get; set; }
        }
        //-------------

        private readonly string _key;
        private readonly string _hash;

        private const string FileName = "temp";

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

        // Удаляем всю временную информацию
        private static void ClearTempData()
        {
            if (File.Exists(FileName + ".zip"))
                File.Delete(FileName + ".zip");

            var directory = new DirectoryInfo(FileName);
            foreach (FileInfo file in directory.GetFiles()) file.Delete();
            foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        }

        public void Run()
        {
            ClearTempData();

            using (var client = new WebClient())
            {
                client.DownloadFile(String.Format("http://smartfetch.io/{0}/get/{1}", _key, _hash), FileName + ".zip");
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(FileName + ".zip", FileName);

            string[] files = Directory.GetFiles(FileName);

            string[] columns = File.ReadAllText(FileName + "/column.txt").Split(',');

            foreach (var file in files)
            {
                if (!file.EndsWith(".json")) continue;

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
                MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("{ \"data\" :" + File.ReadAllText(file) + "}"));

                // В поле response.data в двумерном массиве содержатся ответы
                Response response = (Response)js.ReadObject(ms);
            }

            ClearTempData();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

            gt.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
129
130
131
132
133
134
135
136
137
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Post
    {
        // -----------------    Описание запроса
        [DataContract]
        public class Data
        {
            [DataMember(Name = "column")]
            public string[] Column { get; set; }
            [DataMember(Name = "data")]
            public string[][] SData { get; set; }
        }
        // -----------------------

        //----------------------  Описание ответа
        [DataContract]
        public class Response
        {
            [DataMember(Name = "success")]
            public bool Success { get; set; }
            [DataMember(Name = "duration")]
            public Int32 Duration { get; set; }
            [DataMember(Name = "backgroundColor")]
            public string BackgroundColor { get; set; }
            [DataMember(Name = "message")]
            public string Message { get; set; }
            [DataMember(Name = "hash")]
            public string Hash { get; set; }
        }
        // ---------------------------------

        private string _key = "[API_KEY]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/

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

        // Формируем запрос
        private string FormatJson()
        {
            // Создание объекста, содержащего все параметры запроса
            var data = new Data()
            {
                
                SData = new[]
                {
                    new[] {   },
                    new[] {   },
                    new[] {   }
                }

            };

            // Формируем JSON из объекта
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));

            ser.WriteObject(stream1, data);

            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            string json = sr.ReadToEnd();

            return json;
        }

        // Выполняем запрос к серверу
        private string MakeRequest(string data)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://smartfetch.io/{0}/api/", _key));

            string postData = "task=bingindex";
            postData += "&data=" + data;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(postData);
                streamWriter.Flush();
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
        }

        // Разбирает ответ от сервера
        private Response ParseResponse(string json)
        {
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(json));

            return (Response)js.ReadObject(ms);
        }

        public void Run()
        {
            string request = FormatJson();

            string response = MakeRequest(request);

            Response res = ParseResponse(response);

            if (res.Success)
            {
                Console.WriteLine(String.Format("ok {0}", res.Hash));
            }
            else
            {
                if (res.Message != null)
                    Console.WriteLine(string.Format("error {0}", res.Message));
                else
                    Console.WriteLine("error");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Post pt = new Post("");
            pt.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Get
    {
        // ------------ Описание формата ответа
        [DataContract]
        class Response
        {
            [DataMember(Name = "data")]
            public List<List<String>> Data { get; set; }
        }
        //-------------

        private readonly string _key;
        private readonly string _hash;

        private const string FileName = "temp";

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

        // Удаляем всю временную информацию
        private static void ClearTempData()
        {
            if (File.Exists(FileName + ".zip"))
                File.Delete(FileName + ".zip");

            var directory = new DirectoryInfo(FileName);
            foreach (FileInfo file in directory.GetFiles()) file.Delete();
            foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        }

        public void Run()
        {
            ClearTempData();

            using (var client = new WebClient())
            {
                client.DownloadFile(String.Format("http://smartfetch.io/{0}/get/{1}", _key, _hash), FileName + ".zip");
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(FileName + ".zip", FileName);

            string[] files = Directory.GetFiles(FileName);

            string[] columns = File.ReadAllText(FileName + "/column.txt").Split(',');

            foreach (var file in files)
            {
                if (!file.EndsWith(".json")) continue;

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
                MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("{ \"data\" :" + File.ReadAllText(file) + "}"));

                // В поле response.data в двумерном массиве содержатся ответы
                Response response = (Response)js.ReadObject(ms);
            }

            ClearTempData();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

            gt.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
129
130
131
132
133
134
135
136
137
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Post
    {
        // -----------------    Описание запроса
        [DataContract]
        public class Data
        {
            [DataMember(Name = "column")]
            public string[] Column { get; set; }
            [DataMember(Name = "data")]
            public string[][] SData { get; set; }
        }
        // -----------------------

        //----------------------  Описание ответа
        [DataContract]
        public class Response
        {
            [DataMember(Name = "success")]
            public bool Success { get; set; }
            [DataMember(Name = "duration")]
            public Int32 Duration { get; set; }
            [DataMember(Name = "backgroundColor")]
            public string BackgroundColor { get; set; }
            [DataMember(Name = "message")]
            public string Message { get; set; }
            [DataMember(Name = "hash")]
            public string Hash { get; set; }
        }
        // ---------------------------------

        private string _key = "[API_KEY]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/

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

        // Формируем запрос
        private string FormatJson()
        {
            // Создание объекста, содержащего все параметры запроса
            var data = new Data()
            {
                
                SData = new[]
                {
                    new[] {   },
                    new[] {   },
                    new[] {   }
                }

            };

            // Формируем JSON из объекта
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));

            ser.WriteObject(stream1, data);

            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            string json = sr.ReadToEnd();

            return json;
        }

        // Выполняем запрос к серверу
        private string MakeRequest(string data)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://smartfetch.io/{0}/api/", _key));

            string postData = "task=bingindex";
            postData += "&data=" + data;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(postData);
                streamWriter.Flush();
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
        }

        // Разбирает ответ от сервера
        private Response ParseResponse(string json)
        {
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(json));

            return (Response)js.ReadObject(ms);
        }

        public void Run()
        {
            string request = FormatJson();

            string response = MakeRequest(request);

            Response res = ParseResponse(response);

            if (res.Success)
            {
                Console.WriteLine(String.Format("ok {0}", res.Hash));
            }
            else
            {
                if (res.Message != null)
                    Console.WriteLine(string.Format("error {0}", res.Message));
                else
                    Console.WriteLine("error");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Post pt = new Post("");
            pt.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Get
    {
        // ------------ Описание формата ответа
        [DataContract]
        class Response
        {
            [DataMember(Name = "data")]
            public List<List<String>> Data { get; set; }
        }
        //-------------

        private readonly string _key;
        private readonly string _hash;

        private const string FileName = "temp";

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

        // Удаляем всю временную информацию
        private static void ClearTempData()
        {
            if (File.Exists(FileName + ".zip"))
                File.Delete(FileName + ".zip");

            var directory = new DirectoryInfo(FileName);
            foreach (FileInfo file in directory.GetFiles()) file.Delete();
            foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        }

        public void Run()
        {
            ClearTempData();

            using (var client = new WebClient())
            {
                client.DownloadFile(String.Format("http://smartfetch.io/{0}/get/{1}", _key, _hash), FileName + ".zip");
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(FileName + ".zip", FileName);

            string[] files = Directory.GetFiles(FileName);

            string[] columns = File.ReadAllText(FileName + "/column.txt").Split(',');

            foreach (var file in files)
            {
                if (!file.EndsWith(".json")) continue;

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
                MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("{ \"data\" :" + File.ReadAllText(file) + "}"));

                // В поле response.data в двумерном массиве содержатся ответы
                Response response = (Response)js.ReadObject(ms);
            }

            ClearTempData();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

            gt.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
129
130
131
132
133
134
135
136
137
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Post
    {
        // -----------------    Описание запроса
        [DataContract]
        public class Data
        {
            [DataMember(Name = "column")]
            public string[] Column { get; set; }
            [DataMember(Name = "data")]
            public string[][] SData { get; set; }
        }
        // -----------------------

        //----------------------  Описание ответа
        [DataContract]
        public class Response
        {
            [DataMember(Name = "success")]
            public bool Success { get; set; }
            [DataMember(Name = "duration")]
            public Int32 Duration { get; set; }
            [DataMember(Name = "backgroundColor")]
            public string BackgroundColor { get; set; }
            [DataMember(Name = "message")]
            public string Message { get; set; }
            [DataMember(Name = "hash")]
            public string Hash { get; set; }
        }
        // ---------------------------------

        private string _key = "[API_KEY]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/

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

        // Формируем запрос
        private string FormatJson()
        {
            // Создание объекста, содержащего все параметры запроса
            var data = new Data()
            {
                
                SData = new[]
                {
                    new[] {   },
                    new[] {   },
                    new[] {   }
                }

            };

            // Формируем JSON из объекта
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));

            ser.WriteObject(stream1, data);

            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            string json = sr.ReadToEnd();

            return json;
        }

        // Выполняем запрос к серверу
        private string MakeRequest(string data)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://smartfetch.io/{0}/api/", _key));

            string postData = "task=bingindex";
            postData += "&data=" + data;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(postData);
                streamWriter.Flush();
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
        }

        // Разбирает ответ от сервера
        private Response ParseResponse(string json)
        {
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(json));

            return (Response)js.ReadObject(ms);
        }

        public void Run()
        {
            string request = FormatJson();

            string response = MakeRequest(request);

            Response res = ParseResponse(response);

            if (res.Success)
            {
                Console.WriteLine(String.Format("ok {0}", res.Hash));
            }
            else
            {
                if (res.Message != null)
                    Console.WriteLine(string.Format("error {0}", res.Message));
                else
                    Console.WriteLine("error");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Post pt = new Post("");
            pt.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Get
    {
        // ------------ Описание формата ответа
        [DataContract]
        class Response
        {
            [DataMember(Name = "data")]
            public List<List<String>> Data { get; set; }
        }
        //-------------

        private readonly string _key;
        private readonly string _hash;

        private const string FileName = "temp";

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

        // Удаляем всю временную информацию
        private static void ClearTempData()
        {
            if (File.Exists(FileName + ".zip"))
                File.Delete(FileName + ".zip");

            var directory = new DirectoryInfo(FileName);
            foreach (FileInfo file in directory.GetFiles()) file.Delete();
            foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        }

        public void Run()
        {
            ClearTempData();

            using (var client = new WebClient())
            {
                client.DownloadFile(String.Format("http://smartfetch.io/{0}/get/{1}", _key, _hash), FileName + ".zip");
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(FileName + ".zip", FileName);

            string[] files = Directory.GetFiles(FileName);

            string[] columns = File.ReadAllText(FileName + "/column.txt").Split(',');

            foreach (var file in files)
            {
                if (!file.EndsWith(".json")) continue;

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
                MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("{ \"data\" :" + File.ReadAllText(file) + "}"));

                // В поле response.data в двумерном массиве содержатся ответы
                Response response = (Response)js.ReadObject(ms);
            }

            ClearTempData();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

            gt.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
129
130
131
132
133
134
135
136
137
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Post
    {
        // -----------------    Описание запроса
        [DataContract]
        public class Data
        {
            [DataMember(Name = "column")]
            public string[] Column { get; set; }
            [DataMember(Name = "data")]
            public string[][] SData { get; set; }
        }
        // -----------------------

        //----------------------  Описание ответа
        [DataContract]
        public class Response
        {
            [DataMember(Name = "success")]
            public bool Success { get; set; }
            [DataMember(Name = "duration")]
            public Int32 Duration { get; set; }
            [DataMember(Name = "backgroundColor")]
            public string BackgroundColor { get; set; }
            [DataMember(Name = "message")]
            public string Message { get; set; }
            [DataMember(Name = "hash")]
            public string Hash { get; set; }
        }
        // ---------------------------------

        private string _key = "[API_KEY]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/

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

        // Формируем запрос
        private string FormatJson()
        {
            // Создание объекста, содержащего все параметры запроса
            var data = new Data()
            {
                
                SData = new[]
                {
                    new[] {   },
                    new[] {   },
                    new[] {   }
                }

            };

            // Формируем JSON из объекта
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));

            ser.WriteObject(stream1, data);

            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            string json = sr.ReadToEnd();

            return json;
        }

        // Выполняем запрос к серверу
        private string MakeRequest(string data)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://smartfetch.io/{0}/api/", _key));

            string postData = "task=bingindex";
            postData += "&data=" + data;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(postData);
                streamWriter.Flush();
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
        }

        // Разбирает ответ от сервера
        private Response ParseResponse(string json)
        {
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(json));

            return (Response)js.ReadObject(ms);
        }

        public void Run()
        {
            string request = FormatJson();

            string response = MakeRequest(request);

            Response res = ParseResponse(response);

            if (res.Success)
            {
                Console.WriteLine(String.Format("ok {0}", res.Hash));
            }
            else
            {
                if (res.Message != null)
                    Console.WriteLine(string.Format("error {0}", res.Message));
                else
                    Console.WriteLine("error");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Post pt = new Post("");
            pt.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Get
    {
        // ------------ Описание формата ответа
        [DataContract]
        class Response
        {
            [DataMember(Name = "data")]
            public List<List<String>> Data { get; set; }
        }
        //-------------

        private readonly string _key;
        private readonly string _hash;

        private const string FileName = "temp";

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

        // Удаляем всю временную информацию
        private static void ClearTempData()
        {
            if (File.Exists(FileName + ".zip"))
                File.Delete(FileName + ".zip");

            var directory = new DirectoryInfo(FileName);
            foreach (FileInfo file in directory.GetFiles()) file.Delete();
            foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        }

        public void Run()
        {
            ClearTempData();

            using (var client = new WebClient())
            {
                client.DownloadFile(String.Format("http://smartfetch.io/{0}/get/{1}", _key, _hash), FileName + ".zip");
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(FileName + ".zip", FileName);

            string[] files = Directory.GetFiles(FileName);

            string[] columns = File.ReadAllText(FileName + "/column.txt").Split(',');

            foreach (var file in files)
            {
                if (!file.EndsWith(".json")) continue;

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
                MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("{ \"data\" :" + File.ReadAllText(file) + "}"));

                // В поле response.data в двумерном массиве содержатся ответы
                Response response = (Response)js.ReadObject(ms);
            }

            ClearTempData();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

            gt.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
129
130
131
132
133
134
135
136
137
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Post
    {
        // -----------------    Описание запроса
        [DataContract]
        public class Data
        {
            [DataMember(Name = "column")]
            public string[] Column { get; set; }
            [DataMember(Name = "data")]
            public string[][] SData { get; set; }
        }
        // -----------------------

        //----------------------  Описание ответа
        [DataContract]
        public class Response
        {
            [DataMember(Name = "success")]
            public bool Success { get; set; }
            [DataMember(Name = "duration")]
            public Int32 Duration { get; set; }
            [DataMember(Name = "backgroundColor")]
            public string BackgroundColor { get; set; }
            [DataMember(Name = "message")]
            public string Message { get; set; }
            [DataMember(Name = "hash")]
            public string Hash { get; set; }
        }
        // ---------------------------------

        private string _key = "[API_KEY]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/

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

        // Формируем запрос
        private string FormatJson()
        {
            // Создание объекста, содержащего все параметры запроса
            var data = new Data()
            {
                
                SData = new[]
                {
                    new[] {   },
                    new[] {   },
                    new[] {   }
                }

            };

            // Формируем JSON из объекта
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));

            ser.WriteObject(stream1, data);

            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            string json = sr.ReadToEnd();

            return json;
        }

        // Выполняем запрос к серверу
        private string MakeRequest(string data)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://smartfetch.io/{0}/api/", _key));

            string postData = "task=bingindex";
            postData += "&data=" + data;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(postData);
                streamWriter.Flush();
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    return streamReader.ReadToEnd();
                }
            }
        }

        // Разбирает ответ от сервера
        private Response ParseResponse(string json)
        {
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(json));

            return (Response)js.ReadObject(ms);
        }

        public void Run()
        {
            string request = FormatJson();

            string response = MakeRequest(request);

            Response res = ParseResponse(response);

            if (res.Success)
            {
                Console.WriteLine(String.Format("ok {0}", res.Hash));
            }
            else
            {
                if (res.Message != null)
                    Console.WriteLine(string.Format("error {0}", res.Message));
                else
                    Console.WriteLine("error");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Post pt = new Post("");
            pt.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace ConsoleApplication1
{
    class Get
    {
        // ------------ Описание формата ответа
        [DataContract]
        class Response
        {
            [DataMember(Name = "data")]
            public List<List<String>> Data { get; set; }
        }
        //-------------

        private readonly string _key;
        private readonly string _hash;

        private const string FileName = "temp";

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

        // Удаляем всю временную информацию
        private static void ClearTempData()
        {
            if (File.Exists(FileName + ".zip"))
                File.Delete(FileName + ".zip");

            var directory = new DirectoryInfo(FileName);
            foreach (FileInfo file in directory.GetFiles()) file.Delete();
            foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        }

        public void Run()
        {
            ClearTempData();

            using (var client = new WebClient())
            {
                client.DownloadFile(String.Format("http://smartfetch.io/{0}/get/{1}", _key, _hash), FileName + ".zip");
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(FileName + ".zip", FileName);

            string[] files = Directory.GetFiles(FileName);

            string[] columns = File.ReadAllText(FileName + "/column.txt").Split(',');

            foreach (var file in files)
            {
                if (!file.EndsWith(".json")) continue;

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Response));
                MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("{ \"data\" :" + File.ReadAllText(file) + "}"));

                // В поле response.data в двумерном массиве содержатся ответы
                Response response = (Response)js.ReadObject(ms);
            }

            ClearTempData();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Get gt = new Get(API КЛЮЧ, ИДЕНТИФИКАТОР ЗАДАНИЯ);

            gt.Run();
        }
    }
}