当前位置: 首页>>代码示例>>C#>>正文


C# Reddit.GetPost方法代码示例

本文整理汇总了C#中RedditSharp.Reddit.GetPost方法的典型用法代码示例。如果您正苦于以下问题:C# Reddit.GetPost方法的具体用法?C# Reddit.GetPost怎么用?C# Reddit.GetPost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedditSharp.Reddit的用法示例。


在下文中一共展示了Reddit.GetPost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PostBallot

        public static void PostBallot(Ballot ballot)
        {
            var motion = ballot.Motion;
             if (motion.PostUrl == "")
             {
            return;
             }

             var reddit = new RedditSharp.Reddit(Config.RedditUser, Config.RedditPass, true);
             var post = reddit.GetPost(new Uri(motion.PostUrl));
             post.Comment("###" + ballot.Moderator.Name + "###" + Environment.NewLine
            + "*****" + Environment.NewLine
            + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + @" \(UTC\) : *" + ballot.Choice.ToString() + "*" + Environment.NewLine
            );
        }
开发者ID:pimanac,项目名称:ConsensusBot,代码行数:15,代码来源:RedditClient.cs

示例2: Main

        static void Main(string[] args)
        {
            Console.BufferWidth = 100;//Make console wider for better reading
            Console.SetWindowSize(Console.LargestWindowWidth / 2, Console.LargestWindowHeight / 2);
            Reddit reddit = new Reddit();
            while (reddit.User == null)//Keep trying to login until it works
            {
                Console.Write("Username: ");
                var username = Console.ReadLine();
                Console.Write("Password: ");
                var password = ReadPassword();
                try
                {
                    Console.WriteLine("Logging in...");
                    reddit.LogIn(username, password);
                }
                catch (AuthenticationException)
                {
                    Console.WriteLine("Incorrect login.");
                }
            }
            Console.WriteLine("Logged in.");

            Post p = reddit.GetPost("http://www.reddit.com/r/AskReddit/comments/1m15pa/teachers_of_reddit_what_is_the_funniest_thing/");//Put your post url (with http://) here
            Comment[] comments = p.GetComments();

            Console.WriteLine("Got post comments");

            string output = string.Empty;

            int i = 0;
            foreach (Comment c in comments)
            {
                try
                {
                    string text = c.Body;//Take the text of the string from the comment

                    if (!ContainsBlackListedWords(text))//Make sure the comment isn't a witty one liner (rudimentary)
                    {

                        string[] sentences = text.Split('.');//Split the comment into each setence

                        string sentence = sentences[i.MaxAt(sentences.Length-1)] + ".";//Take a sentence out of the sentence array
                        if (sentence.Length > 2 )//Check if it is a good sentence
                        {
                            sentence.Trim();//Trim spaces from both sides of the sentence.

                            Regex whitespaceremoval = new Regex(@"\s\s+");

                            sentence = whitespaceremoval.Replace(sentence, "");//Apply regex to remove excess spacing inside the sentence (readability)

                            //Regex alphanum = new Regex("[^a-zA-Z0-9. ,-]");

                            //sentence = alphanum.Replace(sentence, "");//Remove crazy symbol using regex (readability)

                            output += sentence;//Add the sentence to the output string

                            i++;//Increment i to continue the paragraph

                            Console.WriteLine("Parsed comment:" + i);//Log success
                        }
                    }
                    else
                    {
                        Console.WriteLine("Failed to parse comment : Comment contained blacklisted word");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to parse comment :" + e.Message);//Error catching for that damn null comment at the end of every post
                }
            }
            Console.WriteLine();//Add spacing
            Console.WriteLine();//""

            Console.Write(output);

            File.WriteAllText("out" + DateTime.Now.Ticks.ToString() + ".txt", output);

            Console.ReadKey();
        }
开发者ID:ruarai,项目名称:redditthreadcombobulator,代码行数:81,代码来源:Program.cs

示例3: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            DisplayTextbox displayTextBox = new DisplayTextbox(textBox2);

            displayTextBox.Clear();
            var reddit = new Reddit();

            Post giveawayPost = null;
            int? randomNumber = null;

            Regex numberPost = new Regex(@"(\d{1,6})");

            try
            {
                displayTextBox.Write("Getting giveaway post...");
                giveawayPost = reddit.GetPost(new Uri(textBox1.Text));
            }
            catch (Exception ex)
            {
                displayTextBox.Write("Failed getting giveaway post",
                    "You sure that's the right URI (alsomake sure to get the full uri from the address bar)");
                return;
            }

            displayTextBox.Write("Post title: ",
                giveawayPost.Title,
                "Comment count: ",
                giveawayPost.CommentCount);

            try
            {
                displayTextBox.Write("Getting random number from random.org...");

                WebRequest randomDotOrgRequest = WebRequest.Create(string.Format(RANDOM_ORG_URI, decimal.Round(randomMin.Value, 0), decimal.Round(randomMax.Value, 0)));
                using (WebResponse resp = randomDotOrgRequest.GetResponse())
                {
                    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                    {
                        randomNumber = int.Parse(sr.ReadToEnd());
                    }
                }
            }
            catch (Exception ex)
            {
                displayTextBox.Write("Failed getting giveaway post", ex);
                return;
            }

            displayTextBox.Write("Random Number: ",
                randomNumber,
                "Getting winning comment...",
                "This might take a while...");

            Dictionary<string, int> nums = giveawayPost.Comments.Where(c => c.Body != null && numberPost.IsMatch(c.Body)).ToDictionary(k => k.Shortlink, elementSelector: x => int.Parse(numberPost.Match(x.Body).Captures[0].Value));
            string winningNumKey = null;
            int? winningNumVal = null;
            int? diff = null;

            for (int i = 0; (winningNumKey == null && winningNumVal == null) && (randomNumber + i < decimal.Round(randomMax.Value, 0) || randomNumber - i > 0); i++)
            {
                foreach (var x in nums)
                {
                    if ((x.Value == randomNumber + i && randomNumber + i < decimal.Round(randomMax.Value, 0))
                        || (x.Value == randomNumber - i && randomNumber - i > decimal.Round(randomMin.Value, 0)))
                    {
                        winningNumKey = x.Key;
                        winningNumVal = x.Value;
                        diff = i;
                        break;
                    }

                    //stop if we're out of range
                    if (randomNumber + i > decimal.Round(randomMax.Value, 0) && randomNumber - i < decimal.Round(randomMin.Value, 0))
                        break;
                }
            }

            if (!string.IsNullOrEmpty(winningNumKey) && winningNumVal.HasValue)
            {
                Comment winningComment = giveawayPost.Comments.FirstOrDefault(w => w.Shortlink == winningNumKey);

                displayTextBox.Write("Winning comment (link): ",
                    winningNumKey,
                    "Winning comment (body): ",
                    winningComment.Body,
                    "Winning comment (commenter): ",
                    winningComment.Author,
                    "Diff: ",
                    diff
                    );
            }
            else
            {
                displayTextBox.Write("What the heck?? not one post in the range? you sure you have that range right?");
            }
        }
开发者ID:gardient,项目名称:RedditRandomNumberGiveawayHelper,代码行数:96,代码来源:MainForm.cs


注:本文中的RedditSharp.Reddit.GetPost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。