Advertisement
Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9.  
  10. namespace TwitchWords
  11. {
  12.     public class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             var cookie = "";
  17.             var words = GetWords().Where(x => x.Length > 3);
  18.             var baseUrl = "https://passport.twitch.tv/usernames/";
  19.             // Get the stream containing content returned by the server.  
  20.  
  21.            
  22.  
  23.             foreach (var word in words)
  24.             {
  25.                 try
  26.                 {
  27.                     var url = baseUrl + word;
  28.                     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  29.                     request.Headers["Cookie"] = cookie;
  30.                     var response = (HttpWebResponse)request.GetResponse();
  31.                     if (response.StatusCode == HttpStatusCode.OK)
  32.                     {
  33.                         // Bad response
  34.                     }
  35.                     else if (response.StatusCode == HttpStatusCode.NoContent)
  36.                     {
  37.                         // Good Resposne
  38.                         Console.WriteLine(word);
  39.                         //Thread.Sleep(5000);
  40.  
  41.                     }
  42.                 }
  43.                 catch
  44.                 {
  45.                     Console.WriteLine("fail");
  46.                 }
  47.                            
  48.             }
  49.  
  50.             Console.WriteLine("End of program");
  51.             Console.ReadKey();
  52.         }
  53.  
  54.         public static List<string> GetWords()
  55.         {
  56.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt");
  57.             var response = (HttpWebResponse)request.GetResponse();
  58.  
  59.             Stream dataStream = response.GetResponseStream();
  60.             // Open the stream using a StreamReader for easy access.  
  61.             StreamReader reader = new StreamReader(dataStream);
  62.             // Read the content.  
  63.             string responseFromServer = reader.ReadToEnd();
  64.             // Clean up the streams and the response.  
  65.             reader.Close();
  66.             response.Close();
  67.  
  68.             return new List<string>(responseFromServer.Split("\n"));
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement