Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Windows.Forms;
- using Newtonsoft.Json;
- using Timer = System.Timers.Timer;
- public static class EnumerableExtension
- {
- public static T PickRandom<T>(this IEnumerable<T> source)
- {
- return source.PickRandom(1).Single();
- }
- public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)
- {
- return source.Shuffle().Take(count);
- }
- public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
- {
- return source.OrderBy(x => Guid.NewGuid());
- }
- }
- namespace FourChanMemeSearch
- {
- internal static class Program
- {
- private static string retrieve_board_json(string board)
- {
- return new WebClient().DownloadString($"https://a.4cdn.org/{board}/catalog.json");
- }
- private static readonly List<string> SeenThreads = new List<string>();
- private static void Scanner()
- {
- var json = retrieve_board_json(board);
- var pages = JsonConvert.DeserializeObject<dynamic>(json);
- foreach (var page in pages)
- {
- dynamic ind = page.threads;
- foreach (var thread in ind)
- {
- dynamic number1 = thread.no;
- var number = (string) number1;
- if (thread.sub == null) continue;
- if (SeenThreads.Contains(number))
- continue;
- dynamic sub = thread.sub.ToString();
- string subject = sub.ToString();
- subject = subject.ToLower();
- SeenThreads.Add(number);
- if (SeenThreads.Count >= 1000)
- SeenThreads.RemoveRange(0, 100);
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write($"{SeenThreads.IndexOf(number)}");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("//");
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.Write($"{WebUtility.HtmlDecode(sub)}{Environment.NewLine}");
- if (!subject.Contains(search)) continue;
- lock (threadList)
- {
- if (threadList.Contains(number)) return;
- threadList.Add(number);
- }
- Process.Start($"https://boards.4chan.org/{board}/thread/{number}");
- }
- }
- }
- private static string board;
- private static string search;
- private static readonly List<string> threadList = new List<string>();
- private static readonly List<string> RandomTitles = new List<string>
- {
- "THE GOYIM KNOW",
- "WE WUZ SEARCHINS",
- "SKYKANGZ SKYKANGZ DO NOT SEARCH",
- "Black Lives Splatter",
- "Moonman Moonman",
- "beep boop im a bot poster",
- "we lost to DRRRRRRUMPFIEKINS? ;_;",
- "Hillary did 9/11",
- "Soros is behind feminism",
- "Post No. 11111111111",
- "Praise kek",
- "Catalog sux",
- "Tfw too intelligent to use catalog",
- "Corrupt The Record"
- };
- private static void Main()
- {
- var scanner = new Timer(7777) {AutoReset = true};
- Console.Title = RandomTitles.PickRandom();
- Console.WriteLine(Environment.NewLine);
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.OutputEncoding = Encoding.Unicode;
- Console.WriteLine($"Defaults to /pol/ and Trump General{Environment.NewLine}");
- Console.WriteLine($"Select board: (Shortname) {Environment.NewLine}");
- Console.ForegroundColor = ConsoleColor.DarkRed;
- try
- {
- board = Console.ReadLine().Trim().ToLower();
- }
- catch
- {
- // ignored
- }
- if (string.IsNullOrEmpty(board))
- board = "pol";
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine($"Enter search parameters: {Environment.NewLine}");
- Console.ForegroundColor = ConsoleColor.DarkRed;
- try
- {
- search = Console.ReadLine().Trim().ToLower();
- }
- catch
- {
- // ignored
- }
- if (string.IsNullOrEmpty(search))
- search = "trump general";
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(Environment.NewLine);
- scanner.Elapsed += delegate { Scanner(); };
- scanner.Enabled = true;
- Console.WriteLine("Enter a number from the index displayed to the left and the thread will open in your browser!");
- while (true)
- {
- var input = string.Empty;
- try
- {
- input = Console.ReadLine().Trim().ToLower();
- }
- catch
- {
- // ignored
- }
- int number;
- if (string.IsNullOrEmpty(input)) continue;
- if (int.TryParse(input, out number))
- {
- if (number < -1 || number >= SeenThreads.Count)
- {
- Console.WriteLine($"{number} was out of range {SeenThreads.Count - 1}!");
- continue;
- }
- var test = SeenThreads[number];
- if (!string.IsNullOrEmpty(test))
- Process.Start($"https://boards.4chan.org/{board}/thread/{test}");
- else
- Console.WriteLine($"Did not find index {number}");
- }
- else
- {
- Console.WriteLine($"Guessing you meant to change your search to {input}! Searching now...");
- search = input;
- }
- }
- Application.Run();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement