static void Main(string[] args)
        {
            _reddit = new Reddit();

            List<Post> posts = GetAllPosts();
            posts.RemoveRange(30, posts.Count - 30);

            Dictionary<string, User> username_user = new Dictionary<string, User>();

            foreach (Post post in posts)
            {
                List<Comment> allCommentsForPost = _reddit.GetComments(post.URL, post.URL, false);
                foreach (Comment comment in allCommentsForPost)
                {
                    string pattern = "&lt;a href=\"(.*?)\"&gt;";
                    Match match = Regex.Match(comment.BodyHTML, pattern);
                    if (match.Success)
                    {
                        if (username_user.ContainsKey(comment.Author) == false)
                            username_user.Add(comment.Author, new User { Username = comment.Author });
                        User user = username_user[comment.Author];
                        Link link = new Link();
                        link.Url = match.Groups[1].Value;
                        link.Theme = post.Title;
                        user.linksPosted.Add(link);

                        username_user[user.Username] = user;
                    }
                }
            }

            List<User> drawbotsFavoriteUsers = new List<User>();
            List<User> users = username_user.Values.ToList();
            foreach (User user in users)
            {
                if (user.linksPosted.Count >= 15)
                    drawbotsFavoriteUsers.Add(user);
            }
            string x = users[0].Username;

            Random rnd = new Random();
            int i = rnd.Next(drawbotsFavoriteUsers.Count);

            User artistOfTheMonth = drawbotsFavoriteUsers[i];

            StreamWriter writer = File.CreateText("artistOfTheMonth.txt");
            writer.WriteLine("beep boop it's time for drawbot's Artist of the Moment!");
            writer.WriteLine();
            writer.WriteLine(artistOfTheMonth.Username + " has been selected.");
            writer.WriteLine();

            foreach (Link link in artistOfTheMonth.linksPosted)
            {
                writer.WriteLine("[" + link.Theme + "](" + link.Url + ")");
                writer.WriteLine();
            }
            writer.Close();
        }
Ejemplo n.º 2
0
        public RobotBrain(IRobot robot,
		                   Reddit reddit,
		                   Config config)
        {
            this.robot = robot;
            this.reddit = reddit;
            this.config = config;
            this.robotSubreddit = config.subreddit;
        }
Ejemplo n.º 3
0
 public static void Main(string[] args)
 {
     //writeDefaultConfig();
     // TODO: error handling
     Config config = Config.fromFile("redditRobotConfig.xml");
     IRobot robot = (IRobot)new MockRobot();
     Reddit reddit = new Reddit(config.username, config.password,
                                config.redditBaseUrl, config.redditApiUrl,
                                config.cookieDomain, config.linkPrefix,
                                config.commentPrefix);
     RobotBrain brain = new RobotBrain(robot,
                                       reddit,
                                       config);
     brain.start();
     Console.ReadKey();
     brain.stop();
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Starting - " + DateTime.Now.ToString());
            ServicePointManager.ServerCertificateValidationCallback = ShittyRemoveCertValidationCallback; // need this for mono apparently
            ParticipationTracker participationTracker = new ParticipationTracker();
            _reddit = new Reddit();

            List<string> postURLs = participationTracker.GetRelevantPostURLs();

            Dictionary<string, User> userDictionary = new Dictionary<string, User>();

            int themeNumber = 0;
            foreach (string postURL in postURLs)
            {
                themeNumber += 1;
                bool useCache = themeNumber > CACHE_AFTER_THIS_MANY_THEMES;

                List<Comment> allCommentsForTheme = _reddit.GetComments(postURL, postURL, useCache);

                foreach (Comment comment in allCommentsForTheme)
                {
                    if (userDictionary.ContainsKey(comment.Author) == false)
                        userDictionary.Add(comment.Author, new User(comment.Author));
                    User user = userDictionary[comment.Author];

                    participationTracker.ParseComment(postURL, comment, ref user);

                    userDictionary[comment.Author] = user;
                }
            }

            List<User> users = userDictionary.Values.ToList();

            CalculateStreaks(ref users, postURLs);
            ExportStatisticsToFile(users, STATS_FOLDER + "Results.txt");
            ExportStatisticsToJson(users, STATS_FOLDER + "Results.json");

            Dictionary<string, Flair> currentFlair = GetCurrentUserFlairDictionary();
            SetFlair(users, currentFlair);

            foreach (User user in users)
            {
                if (user.MostRecentPost >= INACTIVE_CUTOFF_DATE)
                {
                    string fileName = STATS_FOLDER + user.Username + ".json";
                    bool fileChanged = ExportUserStatisticsToFile(user, fileName);
                    if (fileChanged)
                        UploadResults(STATS_FOLDER + user.Username + ".json", STATS_FTP_FOLDER + user.Username + ".json");
                    else
                        Console.WriteLine("No change to file '" + fileName + "'. Ignoring.");
                }
            }

            UploadResults(STATS_FOLDER + "Results.json", "Results.json");
            Console.WriteLine("Done. " + DateTime.Now.ToString());
        }
 public ParticipationTracker()
 {
     _reddit = new Reddit();
 }