Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using Newtonsoft.Json;
  9. using Timer = System.Timers.Timer;
  10.  
  11. public static class EnumerableExtension
  12. {
  13.     public static T PickRandom<T>(this IEnumerable<T> source)
  14.     {
  15.         return source.PickRandom(1).Single();
  16.     }
  17.  
  18.     public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)
  19.     {
  20.         return source.Shuffle().Take(count);
  21.     }
  22.  
  23.     public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
  24.     {
  25.         return source.OrderBy(x => Guid.NewGuid());
  26.     }
  27. }
  28.  
  29. namespace FourChanMemeSearch
  30. {
  31.     internal static class Program
  32.     {
  33.         private static string retrieve_board_json(string board)
  34.         {
  35.             return new WebClient().DownloadString($"https://a.4cdn.org/{board}/catalog.json");
  36.         }
  37.  
  38.         private static readonly List<string> SeenThreads = new List<string>();
  39.  
  40.         private static void Scanner()
  41.         {
  42.             var json = retrieve_board_json(board);
  43.             var pages = JsonConvert.DeserializeObject<dynamic>(json);
  44.  
  45.             foreach (var page in pages)
  46.             {
  47.                 dynamic ind = page.threads;
  48.                 foreach (var thread in ind)
  49.                 {
  50.                     dynamic number1 = thread.no;
  51.                     var number = (string) number1;
  52.                     if (thread.sub == null) continue;
  53.                     if (SeenThreads.Contains(number))
  54.                         continue;
  55.  
  56.                     dynamic sub = thread.sub.ToString();
  57.  
  58.                     string subject = sub.ToString();
  59.                     subject = subject.ToLower();
  60.  
  61.                     SeenThreads.Add(number);
  62.  
  63.                     if (SeenThreads.Count >= 1000)
  64.                         SeenThreads.RemoveRange(0, 100);
  65.  
  66.                     Console.ForegroundColor = ConsoleColor.DarkYellow;
  67.  
  68.                     Console.Write($"{SeenThreads.IndexOf(number)}");
  69.                     Console.ForegroundColor = ConsoleColor.White;
  70.                     Console.Write("//");
  71.                     Console.ForegroundColor = ConsoleColor.DarkGreen;
  72.  
  73.  
  74.                     Console.Write($"{WebUtility.HtmlDecode(sub)}{Environment.NewLine}");
  75.  
  76.                     if (!subject.Contains(search)) continue;
  77.                     lock (threadList)
  78.                     {
  79.                         if (threadList.Contains(number)) return;
  80.                         threadList.Add(number);
  81.                     }
  82.                     Process.Start($"https://boards.4chan.org/{board}/thread/{number}");
  83.                 }
  84.             }
  85.         }
  86.  
  87.         private static string board;
  88.         private static string search;
  89.         private static readonly List<string> threadList = new List<string>();
  90.  
  91.         private static readonly List<string> RandomTitles = new List<string>
  92.         {
  93.             "THE GOYIM KNOW",
  94.             "WE WUZ SEARCHINS",
  95.             "SKYKANGZ SKYKANGZ DO NOT SEARCH",
  96.             "Black Lives Splatter",
  97.             "Moonman Moonman",
  98.             "beep boop im a bot poster",
  99.             "we lost to DRRRRRRUMPFIEKINS? ;_;",
  100.             "Hillary did 9/11",
  101.             "Soros is behind feminism",
  102.             "Post No. 11111111111",
  103.             "Praise kek",
  104.             "Catalog sux",
  105.             "Tfw too intelligent to use catalog",
  106.             "Corrupt The Record"
  107.         };
  108.  
  109.         private static void Main()
  110.         {
  111.             var scanner = new Timer(7777) {AutoReset = true};
  112.             Console.Title = RandomTitles.PickRandom();
  113.             Console.WriteLine(Environment.NewLine);
  114.             Console.ForegroundColor = ConsoleColor.DarkGreen;
  115.             Console.OutputEncoding = Encoding.Unicode;
  116.             Console.WriteLine($"Defaults to /pol/ and Trump General{Environment.NewLine}");
  117.  
  118.             Console.WriteLine($"Select board: (Shortname) {Environment.NewLine}");
  119.             Console.ForegroundColor = ConsoleColor.DarkRed;
  120.  
  121.             try
  122.             {
  123.                 board = Console.ReadLine().Trim().ToLower();
  124.             }
  125.             catch
  126.             {
  127.                 // ignored
  128.             }
  129.  
  130.             if (string.IsNullOrEmpty(board))
  131.                 board = "pol";
  132.  
  133.             Console.ForegroundColor = ConsoleColor.DarkGreen;
  134.  
  135.             Console.ForegroundColor = ConsoleColor.Blue;
  136.             Console.WriteLine($"Enter search parameters: {Environment.NewLine}");
  137.             Console.ForegroundColor = ConsoleColor.DarkRed;
  138.  
  139.             try
  140.             {
  141.                 search = Console.ReadLine().Trim().ToLower();
  142.             }
  143.             catch
  144.             {
  145.                 // ignored
  146.             }
  147.  
  148.             if (string.IsNullOrEmpty(search))
  149.                 search = "trump general";
  150.  
  151.             Console.ForegroundColor = ConsoleColor.White;
  152.             Console.WriteLine(Environment.NewLine);
  153.  
  154.             scanner.Elapsed += delegate { Scanner(); };
  155.  
  156.             scanner.Enabled = true;
  157.             Console.WriteLine("Enter a number from the index displayed to the left and the thread will open in your browser!");
  158.  
  159.             while (true)
  160.             {
  161.                 var input = string.Empty;
  162.  
  163.                 try
  164.                 {
  165.                     input = Console.ReadLine().Trim().ToLower();
  166.                 }
  167.                 catch
  168.                 {
  169.                     // ignored
  170.                 }
  171.  
  172.                 int number;
  173.                 if (string.IsNullOrEmpty(input)) continue;
  174.                 if (int.TryParse(input, out number))
  175.                 {
  176.                     if (number < -1 || number >= SeenThreads.Count)
  177.                     {
  178.                         Console.WriteLine($"{number} was out of range {SeenThreads.Count - 1}!");
  179.                         continue;
  180.                     }
  181.                     var test = SeenThreads[number];
  182.  
  183.                     if (!string.IsNullOrEmpty(test))
  184.                         Process.Start($"https://boards.4chan.org/{board}/thread/{test}");
  185.                     else
  186.                         Console.WriteLine($"Did not find index {number}");
  187.                 }
  188.                 else
  189.                 {
  190.                     Console.WriteLine($"Guessing you meant to change your search to {input}! Searching now...");
  191.                     search = input;
  192.                 }
  193.             }
  194.  
  195.             Application.Run();
  196.         }
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement