Example #1
0
        public void ProcessPostElement(IWebElement postEl)
        {
            var fbPost = new FbPost(postEl);

            if (_sfx.PostExists(fbPost.FbPostId))
            {
                _logger.Debug($"Постът вече съществува: {fbPost.ToString()}");
                return;
            }

            _driver.Hover(postEl);
            _sfx.AddPost(fbPost.FbPostId);
            try
            {
                SubscribeToPost(postEl);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Неуспешно абониране за пост: {fbPost.ToString()}");
            }
            try
            {
#if DEBUG
#else
                AdminCreatePostDb(fbPost);
#endif
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Duplicate"))
                {
                    _logger.Debug($"Постът вече съществува в базата данни");
                }
                else
                {
                    _logger.Error(ex, $"Неуспешно записване в базата данни: {fbPost.ToString()}");
                }
            }
            try
            {
                AdminCreatePost(fbPost);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Неуспешно създаване на пост в админ системата: {fbPost.ToString()}");
            }
        }
Example #2
0
        private void AdminCreatePost(FbPost fbPost)
        {
            if (ConfigurationManager.AppSettings["Admin.Power"].ToUpper() != "ON")
            {
                return;
            }
            if (ConfigurationManager.AppSettings["Admin.ModeWebOrSql"].ToUpper() != "WEB")
            {
                return;
            }

            if (ConfigurationManager.AppSettings["Admin.Power"].ToUpper() != "ON")
            {
                return;
            }

            var humanizer = new Humanizer.Humanizer(_driver);
            var wait      = new WebDriverWait(_driver, TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["Admin.TimeoutSeconds"])));

            _logger.Info($"Записване на пост админ панела: {fbPost.ToString()}");

            _driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["Admin.CreatePostUrl"]);
            wait.Until(ExpectedConditions.ElementIsVisible(By.TagName("iframe")));
            _driver.SwitchTo().Frame(0);
            _driver.FindElement(By.LinkText("Добави известие")).Click();

            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("Import_url")));

            // fill in meta data
            _driver.FindElement(By.Id("Import_url")).SendKeys(fbPost.FbPostUrl);
            _driver.FindElement(By.Id("Import_id_post")).SendKeys(fbPost.FbPostId);
            _driver.FindElement(By.Id("Import_contact_info")).SendKeys(fbPost.FbPostAuthor);

            // fill in post data
            _driver.FindElement(By.CssSelector("a[title='Код']")).Click();
            wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("a[title='Код']")));
            _driver.FindElement(By.ClassName("cke_source")).SetAttribute("value", fbPost.FbFullHtml);

            _driver.FindElement(By.CssSelector("input[type='submit']")).Click();
            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("massiveOperation")));
            humanizer.WaitRandom();
        }
Example #3
0
        private void AdminCreatePostDb(FbPost post)
        {
            if (ConfigurationManager.AppSettings["Admin.Power"].ToUpper() != "ON")
            {
                return;
            }
            if (ConfigurationManager.AppSettings["Admin.ModeWebOrSql"].ToUpper() != "SQL")
            {
                return;
            }

            var con = new MySqlConnection(ConfigurationManager.AppSettings["Admin.ConnectionString"]);

            try
            {
                con.Open();

                string PostTable       = ConfigurationManager.AppSettings["Admin.PostTable"];
                string PostIdCol       = ConfigurationManager.AppSettings["Admin.PostIdCol"];
                string PostAuthorCol   = ConfigurationManager.AppSettings["Admin.PostAuthorCol"];
                string PostUrlCol      = ConfigurationManager.AppSettings["Admin.PostUrlCol"];
                string PostFullHtmlCol = ConfigurationManager.AppSettings["Admin.PostFullHtmlCol"];
                using (var t = con.BeginTransaction())
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandText = $"INSERT INTO {PostTable} ({PostIdCol}, {PostAuthorCol}, {PostUrlCol}, {PostFullHtmlCol}) VALUES ('{post.FbPostId}', '{post.FbPostAuthor}', '{post.FbPostUrl}', '{post.FbFullHtml.Replace("'","''")}')";
                        _logger.Trace(cmd.CommandText);
                        cmd.ExecuteNonQuery();
                    }
                    t.Commit();
                }
            }
            finally
            {
                con.Dispose();
            }
        }
Example #4
0
        public static void Main()
        {
            _logger.Info(" ============== FACEGROUP ==============");
            PrintConfiguration();

            var options = new ChromeOptions();

            options.AddArgument("--disable-notifications");
            string sfxPath = Directory.GetCurrentDirectory() + @"\social-fixer-for-facebook";

            //options.AddArgument(@"--load-extension="+sfxPath);
            options.AddExtensions();
            var driver = new ChromeDriver("selenium", options);
            var sfx    = new SfxConfiguration(ConfigurationManager.AppSettings["SfxConfigurationFile"]);

            bool reverseGroupOrder = ConfigurationManager.AppSettings["ReverseGroupOrder"].ToUpper() == "ON" ? true : false;

            AdminLogin(driver);
            FacebookLogin(driver);

            var groupManager = new FbGroupManager(driver);
            var postManager  = new FbPostManager(driver, sfx);

            IEnumerable <FbGroup> unreadGroups = groupManager.GetUnreadGroups();

            if (reverseGroupOrder)
            {
                _logger.Info($"Обработка на {unreadGroups.Count()} групи с непрочетени публикации в ОБРАТЕН ред");
                foreach (var fbGroup in unreadGroups)
                {
                    _logger.Info($"------------------- Обработка на група: {fbGroup.ToString()} -----------------------");
                    try
                    {
                        IEnumerable <IWebElement> postsEl = groupManager.GetPosts(fbGroup);
                        _logger.Info($"{postsEl.Count()} поста за обработка в група {fbGroup.ToString()}");
                        int countPostsInGroupSuccess = 0;
                        int countPostsInGroupFail    = 0;
                        foreach (var postEl in postsEl)
                        {
                            var fbPost = new FbPost(postEl);
                            _logger.Info($"Обработка на пост: {fbPost.ToString()}");
                            try
                            {
                                postManager.ProcessPostElement(postEl);
                                countPostsInGroupSuccess++;
                            }
                            catch (Exception postEx)
                            {
                                _logger.Error(postEx, $"Грешка при обработка на пост: {fbPost}");
                                countPostsInGroupFail++;
                            }
                        }
                        _logger.Info($"Общо за групата: {countPostsInGroupSuccess} успешно обработени и {countPostsInGroupFail} неуспешни");
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex, $"Грешка при обработка на група '{fbGroup.GroupName}' - {fbGroup.GroupUrl}");
                        continue;
                    }
                } // end foreach group
            }
            else
            {
                _logger.Info($"Обработка на {unreadGroups.Count()} групи с непрочетени публикации в НОРМАЛЕН ред");
                foreach (var fbGroup in unreadGroups)
                {
                    _logger.Info($"------------------- Обработка на група: {fbGroup.ToString()} -----------------------");
                    try
                    {
                        IEnumerable <IWebElement> postsEl = groupManager.GetPosts(fbGroup);
                        _logger.Info($"{postsEl.Count()} поста за обработка в група {fbGroup.ToString()}");
                        int countPostsInGroupSuccess = 0;
                        int countPostsInGroupFail    = 0;
                        foreach (var postEl in postsEl)
                        {
                            var fbPost = new FbPost(postEl);
                            _logger.Info($"Обработка на пост: {fbPost.ToString()}");
                            try
                            {
                                postManager.ProcessPostElement(postEl);
                                countPostsInGroupSuccess++;
                            }
                            catch (Exception postEx)
                            {
                                _logger.Error(postEx, $"Грешка при обработка на пост: {fbPost}");
                                countPostsInGroupFail++;
                            }
                        }
                        _logger.Info($"Общо за групата: {countPostsInGroupSuccess} успешно обработени и {countPostsInGroupFail} неуспешни");
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex, $"Грешка при обработка на група '{fbGroup.GroupName}' - {fbGroup.GroupUrl}");
                        continue;
                    }
                } // end foreach group
            }
        }