private static async Task <bool> TryUpdateArticleData(ArticlePost articlePost, Reddit r, CloudTable articleTable, ILogger log) { bool result = false; Comment comment = r.GetComment(new Uri("https://www.reddit.com" + articlePost.CommentUri)); Post post = (Post)comment.Parent; string articleUrl = post.Url.GetComponents(UriComponents.Host | UriComponents.Path | UriComponents.Scheme, UriFormat.SafeUnescaped); using (HttpResponseMessage articleResponse = await client.GetAsync(articleUrl)) { SeattleTimesArticle seattleTimesArticle = new SeattleTimesArticle(articleResponse); if (seattleTimesArticle.Headline != articlePost.ArticleHeadline) { log.LogInformation("new headline: " + seattleTimesArticle.Headline); articlePost.ArticleHeadline = seattleTimesArticle.Headline; result = true; } if (seattleTimesArticle.ByLineAuthors.FirstOrDefault() != articlePost.ArticleAuthor) { string author = seattleTimesArticle.ByLineAuthors.FirstOrDefault(); log.LogInformation("new author: " + author); articlePost.ArticleAuthor = author; result = true; } if (result) { await articleTable.ExecuteAsync(TableOperation.InsertOrReplace(articlePost)); } } return(result); }
static void Main(string[] args) { var webagent = new BotWebAgent("Zephandrypus", "meeko011", "KjwX25olhbEI4w", "vVmP-rTXj6EX43iGZkzywi-X4xo", "https://example.com"); var reddit = new Reddit(webagent, true); var user = reddit.User; var saved = user.GetSaved(Sort.Top, 100, FromTime.Year).Where(p => p.Kind == "t1"); saved.SaveAs(@"E:\RedditBots\SavedComments.txt"); var savedFull = new SortedDictionary <string, Comment[]>( saved.Select( p => reddit.GetComment( new Uri(p.Shortlink) ) ).GroupBy( c => c.Subreddit.ToLower(), c => c ).ToDictionary( s => s.Key, s => s.ToArray() ) ); savedFull.SaveAs(@"E:\RedditBots\SavedCommentsFull.txt"); var savedAskreddit = savedFull["askreddit"]; savedAskreddit.SaveAs(@"E:\RedditBots\SavedCommentsAskreddit.txt"); savedAskreddit = savedAskreddit.Where( c => ( c.Body.Contains("lottery") || c.Body.Contains("money") ) && ( c.Body.Contains("lawyer") || c.Body.Contains("broker") ) ).OrderByDescending(c => c.Body.Length).ToArray(); savedAskreddit.SaveAs(@"E:\RedditBots\SavedAskredditLottery.txt"); foreach (var comment in savedAskreddit) { Console.WriteLine(comment.LinkTitle + " - " + comment.Shortlink + " - " + comment.Score); } Console.ReadLine(); }
public RedditSharp.Things.Comment GetComment(string subreddit, string name, string linkName) { return(reddit.GetComment(subreddit, name, linkName)); }
public void retrieveFile(String filename) { Post post = RedditFSUtils.lookupFile(filename, sub); if (post == null) { Console.WriteLine("Failed to find file specified."); } else { var output = File.Create(dirpath + filename); Comment currComment = post.Comments.First(); String prevId = currComment.Id; int i = 0; do { Console.Write("Reading block " + i + "..."); byte[] b; try { b = Convert.FromBase64String(currComment.Body); } catch (ArgumentNullException) { //So this is a rather meaty catch block. Essentially, redditSharp only fetches comment chains 10 deep as far as I can tell. //This catch block essentially just re-retrieves the comment chain where it was left off when that occurs. Console.WriteLine("Comment with parent id " + prevId + " was null. Attemping to refetch from post " + post.Id); var thing = (Comment)reddit.GetThingByFullname(currComment.ParentId); var parentFull = reddit.GetComment(new System.Uri(thing.Shortlink)); if (parentFull != null) { Console.WriteLine("Successfully retrieved new root. Retrying block."); try { Console.Write("Reading block " + i + "..."); currComment = parentFull.Comments.First(); b = Convert.FromBase64String(currComment.Body); } catch (ArgumentNullException) { Console.WriteLine("Failed again after failover. Aborting."); return; } } else { Console.WriteLine("Failed to find parent in root. Aborting."); return; } } Console.WriteLine(" writing buffer of size " + b.Length + "B to disk"); output.Write(b, 0, b.Length); i++; //Block counter; prevId = currComment.Id; //need this for recovery currComment = currComment.Comments.Count > 0 ? currComment.Comments.First() : null; } while (currComment != null); Console.Write("Retrieved file " + filename + " to dir " + dirpath); } }
static void Main() { Console.Title = "BookHorseBot"; List <string> ignoredUsers = new List <string> { "nightmirrormoon" }; if (string.IsNullOrEmpty(Default.FF_Token)) { string receiveStream = FimFictionGetAuthToken(); FfAuthorization authorization = JsonConvert.DeserializeObject <FfAuthorization>(receiveStream); Default.FF_Token = authorization.access_token; Default.Save(); } BotClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); BotClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Default.FF_Token); BotWebAgent webAgent = new BotWebAgent(Default.R_Username, Default.R_Password, Default.R_client_id, Default.R_client_secret, "https://google.com"); Reddit reddit = new Reddit(webAgent, true); reddit.LogIn(Default.R_Username, Default.R_Password); string redditName = reddit.User.FullName; if (redditName.ToLower() == Default.R_Username.ToLower()) { Console.WriteLine("Logged in!"); } Subreddit subreddit = reddit.GetSubreddit("mylittlepony"); IEnumerable <Comment> comments = subreddit.CommentStream.Where(c => !ignoredUsers.Contains(c.AuthorName.ToLower()) && c.CreatedUTC >= DateTime.UtcNow.AddMinutes(-5) ); foreach (Comment comment in comments) { if (!comment.Body.Contains("{") && !comment.Body.Contains("}")) { continue; } Comment qualifiedComment = reddit.GetComment(new Uri(comment.Shortlink)); if (qualifiedComment.Comments.All(x => x.AuthorName != redditName)) { List <string> list = ExtractStoryNames(comment); if (list.Count > 0) { List <Story.Rootobject> stories = GetPostText(list); string postReplyBody = GeneratePostBody(stories); comment.Reply(postReplyBody); Console.WriteLine($"Reply posted to {comment.AuthorName}!"); } } } }
public static async Task AsyncMain() { IConfigurationBuilder builder = new ConfigurationBuilder(); builder.SetBasePath(Directory.GetCurrentDirectory()); builder.AddJsonFile("config.json"); IConfigurationRoot securityConfiguration = builder.Build(); RedditApplication application = new RedditApplication() { ApplicationName = "FrdModBot", ApplicationVersion = "0.1", AuthorUsername = "******", Client = new RedditClient() { ClientId = securityConfiguration["client:id"], ClientSecret = securityConfiguration["client:secret"] } }; RedditUser user = new RedditUser() { Username = securityConfiguration["user:username"], Password = securityConfiguration["user:password"] }; string subreddit = securityConfiguration["subreddit"]; Reddit reddit = new Reddit(application, user); ListingReader modQueue = new ListingReader(await reddit.ModQueue(subreddit)); List <Comment> comments = new List <Comment>(); List <Link> links = new List <Link>(); modQueue.CommentHandler = comment => { comments.Add(comment); }; modQueue.LinkHandler = link => { links.Add(link); }; await modQueue.Handle(); foreach (Comment comment in comments) { if (!String.IsNullOrEmpty(comment.ParentId)) { ItemKind kind = ItemHelpers.KindFromItemId(comment.ParentId); switch (kind) { case ItemKind.Comment: { Comment parent = await reddit.GetComment(comment.LinkId, comment.ParentId); if (parent.Replies != null) { var x = 1; } } break; case ItemKind.Link: { Link parent = await reddit.GetLink(comment.ParentId); var x = parent.NumComments; } break; } } } return; }