private static void Main(string[] args) { bool clear = true; Logger.Init(Path.Combine(Environment.CurrentDirectory, "Log.txt"), Path.Combine(Environment.CurrentDirectory, "Error.txt")); for (int i = 0; i < 1; i++) { using ( var cList = new CommentSet(Path.Combine(Directory.GetCurrentDirectory(), "Comments.jsv"))) using (var vList = new PostSet(Path.Combine(Directory.GetCurrentDirectory(), "Posts.jsv"))) { RedditSharp.RedditBot.Bot bot = new RedditSharp.RedditBot.Bot(vList, cList, false); clear = false; } } }
// public const int MinCommentLength = 8; public Bot(PostSet voteableSet, CommentSet cList, bool clearCheckedPosts, bool simpleCompareOnly = true, bool verbose = true) { if (!File.Exists(CredentialstPath)) { throw new FileNotFoundException($"{CredentialstPath} does not exist"); } SimpleCompareOnly = simpleCompareOnly; Verbose = verbose; CheckedLogger.Init(Environment.CurrentDirectory, "Checked", clearCheckedPosts); Reddit = new Reddit(); Reddit.Posts = voteableSet; Reddit.Comments = cList; var creds = File.ReadAllLines(CredentialstPath); User = Reddit.LogIn(creds[0], creds[1], checkPath: Path.Combine(Environment.CurrentDirectory, "Checked.xml")); var sub = Reddit.GetSubreddit("SciBotTest");//Reddit.RSlashAll; // var sub = Reddit.RSlashAll; CheckRecentPosts(sub); Logger.TearDown(); }
public static void UpdateTitles(string site, string subdir) { string datadir = "..\\..\\..\\..\\data\\" + site + "\\"; string postsdir = Path.Combine(datadir, subdir + "\\"); Console.WriteLine("Updating titles for saved answers ({0}, {1})...", site, subdir); PostSet posts = PostSet.LoadFromDir(postsdir, site); Dictionary <int, Question> questions = posts.Questions; Console.WriteLine("Answers without parent question: {0}", posts.MarkdownAnswers.Count); int n = 0; List <int> question_ids = new List <int>(posts.MarkdownAnswers.Count); foreach (int a in posts.MarkdownAnswers.Keys) { try { question_ids.Add(posts.MarkdownAnswers[a].QuestionId); n++; //if (n > 70) break; } catch (Exception ex) { Console.WriteLine(ex.GetType() + ": " + ex.Message); //System.Threading.Thread.Sleep(20 * 1000); } } Dictionary <int, QuestionMarkdown> loaded = LoadQuestionsSequence(site, question_ids); foreach (int a in posts.MarkdownAnswers.Keys) { try { int key = posts.MarkdownAnswers[a].QuestionId; if (!loaded.ContainsKey(key)) { Console.WriteLine("Not found Q" + key.ToString()); continue; } QuestionMarkdown qmd = loaded[key]; string newtitle = posts.MarkdownAnswers[a].Title; if (!String.IsNullOrEmpty(qmd.Title)) { newtitle = "Ответ на \"" + qmd.Title + "\""; } posts.MarkdownAnswers[a].Title = newtitle; string filepath = Path.Combine(postsdir, "A" + a.ToString() + ".md"); TextWriter wr = new StreamWriter(filepath, false, Encoding.UTF8); using (wr) { posts.MarkdownAnswers[a].ToMarkdown(wr); } } catch (Exception ex) { Console.WriteLine(ex.GetType() + ": " + ex.Message); } } }