protected static List<Comment> GetTopComments(Post post)
        {
            Console.WriteLine(LOG_GET_COMMENTS);

            var allComments = post.GetComments();
            var topComments = GetTopCommentList(allComments);
            List<Comment> comments = new List<Comment>();

            foreach (Comment comment in topComments)
            {
                comments.Add(comment);
            }

            return comments;
        }
 public static DateTime getPostTime(Post p) { return p.Created; }
 public static int getNumDownvotes(Post p) { return p.Downvotes; }
 public static int getNumUpvotes(Post p) { return p.Upvotes; }
 public static int getTitleLength(Post p) { return p.Title.Length; }
        // Post accessors

        public static string getTitle(Post p) { return p.Title; }
Exemple #7
0
        static void ScreenshotWorker(object arg)
        {
            int worker = (int)arg;
            Console.WriteLine("Worker #"+worker+" online");
            while (true)
            {
                Post[] work = new Post[worker == 1 ? Work1.Count : Work2.Count];
                if(worker == 2) Work2.CopyTo(work);
                else Work1.CopyTo(work);

                if (work.Length == 0) Thread.Sleep(100);
                foreach (Post post in work)
                {
                    var path = "screenshots/" + Path.GetRandomFileName().Replace(".", "") + ".png";
                    Process process = new Process();
                    if (IsRunningOnMono())
                    {
                        //we will now assume we're running in linux...
                        var args = string.Format("--auto-servernum wkhtmltoimage --use-xserver --width 1366 \"{1}\" \"{0}\"", path, post.Url);
                        Console.WriteLine(">>> xvfb-run " + args);
                        process.StartInfo = new ProcessStartInfo("xvfb-run", args);
                        process.Start();
                        process.WaitForExit();
                    }
                    else
                    {
                        //we're in windows
                        path = path.Replace("/", "\\");
                        var args = string.Format("--width 1366 \"{1}\" \"{0}\"", path, post.Url);
                        Console.WriteLine(">>> wkhtmltoimage " + args);
                        process.StartInfo = new ProcessStartInfo("wkhtmltopdf\\wkhtmltoimage.exe", args);
                        process.Start();
                        process.WaitForExit();
                    }
                    if (!File.Exists(path)) Console.WriteLine("Failed to take scrn of " + post.Url);
                    else
                    {
                        /*try
                        {*/
                            //Don't upload anymore...
                            //Upload(path);

                            var message = template;
                            message = message.Replace("{url}", www + Path.GetFileName(path));
                            message = message.Replace("\\n", "\n");
                            post.Comment(message);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("Successfully mirrored & commented " + post.Id);
                            Console.ForegroundColor = ConsoleColor.Gray;
                        /*}
                        catch (Exception z)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Failed to upload " + path + "\r\n" + z.ToString());
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }*/
                    }
                }

            }
        }
Exemple #8
0
        static bool Scan(Post post)
        {
            if (post.IsSelfPost) return false;
            if(ProcessedURLs.Contains(post.Url)) return false;
            else ProcessedURLs.Add(post.Url);
            if (Regex.IsMatch(post.Url, @"((\.exe|\.gif|\.jpg|\.pdf|\.png|\.tga))$")) return false;

            //domain detection

            var subdomain = Regex.Matches(post.Url, "(?:http://|https://)[\\d.A-Za-z]+\\.([\\dA-Za-z]+\\.[A-Za-z]+)");
            var domain = Regex.Matches(post.Url, "(?:http://|https://)([\\dA-Za-z]+\\.[\\d.A-Za-z]+)");

            if (domain.Count != 1) return false;
            string rdomain = domain[0].Groups[1].Value;
            if (popular.isBlackListed(rdomain)) return false;
            if (subdomain.Count == 1)
            {
                string rsubdomain = subdomain[0].Groups[1].Value;
                if(popular.isBlackListed(rsubdomain)) return false;
            }

            //Console.WriteLine("[PASS] " + domain[0].Groups[1] +"/"+(subdomain.Count > 0 ? subdomain[0].Groups[1].Value : "<none>"));
            return true;
            //return false;
        }
 /// <summary>
 /// Constructs an <see cref="IAsyncEnumerable{T}"/> for the <see cref="Comment"/>(s) on the <paramref name="post"/>.
 /// This will result in multiple requests for larger comment trees as it will resolve all <see cref="More"/> objects
 /// it encounters.
 /// </summary>
 /// <param name="agent"> WebAgent necessary for requests</param>
 /// <param name="post">The <see cref="Post"/> of the comments section to enumerate</param>
 /// <param name="limitPerRequest">Initial request size, ignored by the MoreChildren endpoint</param>
 public CommentsEnumarable(IWebAgent agent, Post post, int limitPerRequest = 0)
 {
     this.post  = post;
     this.agent = agent;
     limit      = limitPerRequest;
 }