Advertisement
Doktorkrab

Parser Intellecta

May 16th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.IO;
  8. using VkNet;
  9. using VkNet.Enums.Filters;
  10. using VkNet.Model.RequestParams;
  11. namespace Lksh
  12. {
  13.     class Program
  14.     {
  15.         static WebClient client = new WebClient();
  16.         static VkApi api = new VkApi();
  17.  
  18.         static string DownloadPage()
  19.         {
  20.             client.Encoding = System.Text.Encoding.UTF8;
  21.             return (new StreamReader(client.OpenRead("http://intellect.lokos.net/sessions/letters.php"),System.Text.Encoding.GetEncoding("windows-1251"))).ReadToEnd();
  22.         }
  23.         static long SendMessage(string message)
  24.         {
  25.             return api.Messages.Send(new MessagesSendParams
  26.             {
  27.                 PeerId = 2000000000 + 17,
  28.                 Domain = "https2130706433",
  29.                 Message = message,
  30.  
  31.             });
  32.  
  33.         }
  34.         static void Main(string[] args)
  35.         {
  36.  
  37.             string login = "+79533647653";
  38.             string password = "Awotxuivamaneparol";
  39.  
  40.             api.Authorize(new ApiAuthParams
  41.             {
  42.                 ApplicationId = 5461330,
  43.                 Login = login,
  44.                 Password = password,
  45.                 Settings = Settings.All
  46.  
  47.             });
  48.             long id = api.UserId.Value;
  49.             string prev;
  50.             try
  51.             {
  52.                 var baf = new StreamReader(@"C:\IntellectParser\buffer.txt");
  53.                 prev = baf.ReadToEnd();
  54.                 baf.Close();
  55.  
  56.             }
  57.             catch (FileNotFoundException e)
  58.             {
  59.                 prev = DownloadPage();
  60.                 Console.WriteLine("Файл буффера не найден! Он будет создан");
  61.                 System.IO.File.WriteAllText(@"C:\IntellectParser\buffer.txt", "");
  62.             }
  63.             catch (DirectoryNotFoundException e)
  64.             {
  65.                 prev = DownloadPage();
  66.                 Console.WriteLine("Директория не найдена!");
  67.                 Directory.CreateDirectory(@"c:\IntellectParser");
  68.                 System.IO.File.WriteAllText(@"C:\IntellectParser\buffer.txt", "");
  69.             }
  70.             while (true)
  71.             {
  72.                 string now = DownloadPage();
  73.                 if (now.Length != prev.Length)
  74.                 {
  75.                     Console.WriteLine("Изменения на сайте Интеллекта");
  76.                     SendMessage("Какие-то изменения на сайте Интеллекта");
  77.                     prev = now;
  78.                     System.IO.File.WriteAllText(@"C:\IntellectParser\buffer.txt", now);
  79.                 }
  80.                 System.Threading.Thread.Sleep(900000);
  81.             }
  82.  
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement