static void Main(string[] args) { Console.WriteLine("------------------------Program Start------------------------\n"); ConfigProvider.GetGeneralConfig(); ConfigProvider.GetRedditConfig(); // checks and creates confing on startup var generalconfig = ConfigProvider.GetGeneralConfig(); Console.WriteLine(string.Empty); //var Options = BaseUi.ui(); #region Create stuff List <List <DirectoryInfo> > ParentDirList = new List <List <DirectoryInfo> >(); ParentDirList.Add(CreateFolder.DirectoryCreate(generalconfig.DefualtOutputPath)); RedditClass.getpost(ParentDirList[0]); #endregion }
public static void getpost(List <DirectoryInfo> DirList) { var RedditConfig = ConfigProvider.GetRedditConfig(); var GeneralConfig = ConfigProvider.GetGeneralConfig(); var reddit = new RedditClient(appId: RedditConfig.AppId, refreshToken: RedditConfig.RefreshToken, appSecret: RedditConfig.ClientSecret); var subreddit = reddit.Subreddit("AskReddit"); Console.WriteLine($"App Id: {RedditConfig.AppId}\nRefresh Token: {RedditConfig.RefreshToken}\nClient Secret: {RedditConfig.ClientSecret}"); #region Console.WriteLine("\nGetting post index..."); int postindex = GetIndex(0); Console.WriteLine("\nFinished getting post index"); Console.WriteLine("\nGetting comments to list"); List <string> comments = GetText(postindex); Console.WriteLine("\nFinished getting comments to list"); Console.WriteLine("\nWriting comments to file"); WriteToFile(comments); Console.WriteLine("\nFinished writing comments to file"); #endregion int GetIndex(int postindex) { var post = subreddit.Posts.Hot[postindex]; if (post.Comments.Top.Count != 0) { return(postindex); } else { postindex++; return(GetIndex(postindex)); } } List <string> GetText(int index) { var post = subreddit.Posts.Hot[index]; List <string> CommentText = new List <string>(); int CommentLimit = 10; int CurrentComments = 0; foreach (Comment comment in post.Comments.Top) { CommentText.Add(comment.Body); CurrentComments++; if (CurrentComments >= CommentLimit) { break; } } return(CommentText); } void WriteToFile(List <string> comments) { File.WriteAllLines(DirList[1].FullName + @"\TestTxt.txt", comments); } }
public static OptionsClass ui() { Uri Url = null; DirectoryInfo OutputPath = null; var config = ConfigProvider.GetGeneralConfig(); Url = GetUri(); Console.WriteLine($"Url is: {Url}"); OutputPath = GetDirectoryInfo(); Console.WriteLine($"Output path is: {OutputPath}\n"); return(new OptionsClass(Url, OutputPath)); Uri GetUri() { Console.Write("Enter url (leave blank for default): "); string UriText = Console.ReadLine(); try { return(new Uri(UriText, UriKind.Absolute)); } catch (UriFormatException) { if (UriText == "") { return(config.DefaultUri); } else { Console.WriteLine("failed to get proper url"); return(GetUri()); } } } DirectoryInfo GetDirectoryInfo() { Console.Write("WARNING - MAKE SURE THIS IS CORRECT\nEnter output path (leave blank for default): "); string OutputText = Console.ReadLine(); try { return(new DirectoryInfo(OutputText)); } catch (ArgumentException) { if (OutputText == "") { Console.WriteLine("Getting default file path"); return(new DirectoryInfo(config.DefualtOutputPath)); } } catch (Exception e) { Console.WriteLine(e); return(GetDirectoryInfo()); } return(GetDirectoryInfo()); } }