Exemplo n.º 1
0
        public DateTime LikePost(bool enableVoices, int banLength, DateTime likingBannedUntil, string instagram_post_user)
        {
            foreach (var obj in _IwebDriver.FindElements(By.TagName("a")))
            {
                if (obj.Text.ToUpper().Contains("LIKE") && !obj.Text.ToUpper().Contains("UNLIKE"))
                {
                    if (enableVoices)
                    {
                        C_voice_core.speak($"liking");
                    }
                    obj.Click();
                    if (enableVoices)
                    {
                        C_voice_core.speak($"done");
                    }
                    new Classes.C_DataLayer().SaveInstaUser(IU: new Classes.InstaUser()
                    {
                        username = instagram_post_user.Replace(" ", "_"), date_last_liked = DateTime.Now
                    });
                    Thread.Sleep(1 * 1000);
                    break;
                    //if (obj.Text.ToUpper().Contains("LIKE") && !obj.Text.ToUpper().Contains("UNLIKE"))
                    //{
                    //    // like failed, or another window popped up
                    //    if (enableVoices) C_voice_core.speak($"like failed, I will stop liking for {banLength} minutes.");
                    //    likingBannedUntil = DateTime.Now.AddMinutes(banLength);
                    //}
                    //break;
                }
            }

            return(DateTime.Now); // likingBannedUntil;  TODO, fix post like popup incorrectly results in like fail
        }
Exemplo n.º 2
0
 internal void SaveCurrentStats(int followers, int following, int posts)
 {
     try
     {
         using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
         {
             using (SQLiteCommand SQLcommand = new SQLiteCommand("insert into stat_log (followers, following, posts, datetime) " + "select @followers, @following, @posts, @datetime ", _conn))
             {
                 SQLcommand.Parameters.AddWithValue("followers", followers);
                 SQLcommand.Parameters.AddWithValue("following", following);
                 SQLcommand.Parameters.AddWithValue("posts", posts);
                 SQLcommand.Parameters.AddWithValue("datetime", DateTime.Now.ToString(SQLiteDateTimeFormat));
                 if (_conn.State != System.Data.ConnectionState.Open)
                 {
                     _conn.Open();
                 }
                 SQLcommand.ExecuteNonQuery();
                 _conn.Close();
             }
         }
         //C_voice_core.speak("saved stats to database");
     }
     catch (InvalidOperationException se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     catch (Exception se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
 }
Exemplo n.º 3
0
 public DateTime FollowSuggested(bool enableVoices, int banLength, DateTime followingBannedUntil)
 {
     foreach (var obj in _IwebDriver.FindElements(By.TagName("button")))
     {
         if (obj.Text.ToLower().Trim().Contains("follow"))
         {
             try
             {
                 obj.Click();
                 Thread.Sleep(2 * 1000);
                 if (!obj.Text.ToLower().Trim().Contains("following"))
                 {
                     if (enableVoices)
                     {
                         C_voice_core.speak($"following failed, I will stop following for {banLength} minutes.");
                     }
                     followingBannedUntil = DateTime.Now.AddMinutes(banLength);
                     break;
                 }
             }
             catch
             {
                 if (enableVoices)
                 {
                     C_voice_core.speak($"follow failed");
                 }
             }
         }
     }
     return(followingBannedUntil);
 }
Exemplo n.º 4
0
 public static void TestDatabase(bool enableVoices)
 {
     if (enableVoices)
     {
         C_voice_core.speak($"testing db");
     }
     try
     {
         new Classes.C_DataLayer().AddInstaUser(new Classes.InstaUser()
         {
             username = "******"
         });
         if (enableVoices)
         {
             C_voice_core.speak($"db test passed");
         }
     }
     catch (InvalidOperationException ee)
     {
         if (enableVoices)
         {
             C_voice_core.speak($"SQLite invalid operation error {ee.InnerException.Message}", true);
         }
         MessageBox.Show($"SQLite invalid operation error {ee.InnerException.Message}");
     }
     catch (Exception ee)
     {
         if (enableVoices)
         {
             C_voice_core.speak($"SQLite error {ee.InnerException.Message}", true);
         }
         MessageBox.Show($"SQLite error {ee.InnerException.Message}");
     }
 }
Exemplo n.º 5
0
 public InstaUser GetInstaUser(InstaUser IU)
 {
     C_voice_core.speak("database GetInstaUser");
     try
     {
         using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
         {
             // IU passed in is just a username, populate all other fields then return
             using (SQLiteCommand SQLcommand = new SQLiteCommand("select * from insta_users WHERE username = @username);", _conn))
             {
                 SQLcommand.Parameters.AddWithValue("username", IU.username);
                 if (_conn.State != System.Data.ConnectionState.Open)
                 {
                     _conn.Open();
                 }
                 using (SQLiteDataReader rdr = SQLcommand.ExecuteReader())
                 {
                     if (rdr.Read()) // there can only ever be 1 row
                     {
                         if (DateTime.TryParse(rdr["date_created"].ToString(), out DateTime _date_created))
                         {
                             IU.date_created = _date_created;
                         }
                         if (DateTime.TryParse(rdr["date_followed_them"].ToString(), out DateTime _date_followed_them))
                         {
                             IU.date_followed_them = _date_followed_them;
                         }
                         if (DateTime.TryParse(rdr["date_followed_back_detected"].ToString(), out DateTime _date_followed_back_detected))
                         {
                             IU.date_followed_back_detected = _date_followed_back_detected;
                         }
                         if (DateTime.TryParse(rdr["date_last_commented"].ToString(), out DateTime _date_last_commented))
                         {
                             IU.date_last_commented = _date_last_commented;
                         }
                         if (DateTime.TryParse(rdr["date_last_liked"].ToString(), out DateTime _date_last_liked))
                         {
                             IU.date_last_liked = _date_last_liked;
                         }
                     }
                     else
                     {
                         IU.error = "no record for user";
                         C_voice_core.speak(IU.error);
                     }
                     _conn.Close();
                 }
             }
         }
     }
     catch (InvalidOperationException se)
     {
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     return(IU);
 }
Exemplo n.º 6
0
 // REMEBER spaces at end of each line in SQL to avoid SQL error
 public bool SaveInstaUser(InstaUser IU)
 {
     // start by calling AddInstaUser,which will create it if not exists
     AddInstaUser(IU);
     try
     {
         using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
         {
             // C_voice_core.speak("db SaveInstaUser");
             // now we know they exist, we can update all other fields
             using (SQLiteCommand SQLcommand = new SQLiteCommand("update insta_users set " +
                                                                 "date_followed_them             = (case when @date_followed_them = @SQLiteNullDateString then date_followed_them else @date_followed_them end), " +
                                                                 "date_unfollowed_them           = (case when @date_unfollowed_them = @SQLiteNullDateString then date_unfollowed_them else @date_unfollowed_them end), " +
                                                                 "date_followed_back_detected    = (case when @date_followed_back_detected = @SQLiteNullDateString then date_followed_back_detected else @date_followed_back_detected end), " +
                                                                 "date_last_commented            = (case when @date_last_commented = @SQLiteNullDateString then date_last_commented else @date_last_commented end), " +
                                                                 "date_last_liked                = (case when @date_last_liked = @SQLiteNullDateString then date_last_liked else @date_last_liked end), " +
                                                                 "date_last_updated              = @date_last_updated " +
                                                                 "where username=@username " +
                                                                 "", _conn))
             {
                 SQLcommand.Parameters.AddWithValue("username", IU.username);
                 SQLcommand.Parameters.AddWithValue("date_followed_them", IU.date_followed_them != null ? IU.date_followed_them.ToString(SQLiteDateTimeFormat) : "");
                 SQLcommand.Parameters.AddWithValue("date_unfollowed_them", IU.date_unfollowed != null ? IU.date_unfollowed.ToString(SQLiteDateTimeFormat) : "");
                 SQLcommand.Parameters.AddWithValue("date_followed_back_detected", IU.date_followed_back_detected != null ? IU.date_followed_back_detected.ToString(SQLiteDateTimeFormat) : "");
                 SQLcommand.Parameters.AddWithValue("date_last_commented", IU.date_last_commented != null ? IU.date_last_commented.ToString(SQLiteDateTimeFormat) : "");
                 SQLcommand.Parameters.AddWithValue("date_last_liked", IU.date_last_liked != null ? IU.date_last_liked.ToString(SQLiteDateTimeFormat) : "");
                 SQLcommand.Parameters.AddWithValue("date_last_updated", DateTime.Now.ToString(SQLiteDateTimeFormat));
                 SQLcommand.Parameters.AddWithValue("SQLiteNullDateString", SQLiteNullDateString);
                 if (_conn.State != System.Data.ConnectionState.Open)
                 {
                     _conn.Open();
                 }
                 SQLcommand.ExecuteNonQuery();
                 _conn.Close();
             }
         }
     }
     catch (InvalidOperationException se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         IU.error = se.Message;
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     catch (Exception se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         IU.error = se.Message;
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     return(true);
 }
Exemplo n.º 7
0
 public void CreateInstagramPost(bool enableVoices)
 {
     foreach (var obj1 in _IwebDriver.FindElements(By.TagName("input")))
     {
         if (obj1.GetAttribute("type") == "file")
         {
             if (enableVoices)
             {
                 C_voice_core.speak($"setting image");
             }
             obj1.SendKeys(@"C:\test.png");
             Thread.Sleep(5 * 1000); // wait for page to change
             if (enableVoices)
             {
                 C_voice_core.speak($"uploading");
             }
             _IwebDriver.FindElement(By.TagName("form")).Submit(); // seems to submit but image does not apear on page, maybe it's the wrong form.
             Thread.Sleep(5 * 1000);                               // wait for page to change
             foreach (var obj2 in _IwebDriver.FindElements(By.TagName("button")))
             {
                 if (obj2.Text.ToUpper().Contains("next"))
                 {
                     if (enableVoices)
                     {
                         C_voice_core.speak($"next");
                     }
                     obj2.Click();
                     Thread.Sleep(5 * 1000); // wait for page to change
                 }
                 else if (obj2.Text.ToUpper().Contains("share"))
                 {
                     if (enableVoices)
                     {
                         C_voice_core.speak($"share");
                     }
                     obj2.Click();
                     Thread.Sleep(5 * 1000); // wait for page to change
                     break;
                 }
             }
             break;
         }
     }
     if (enableVoices)
     {
         C_voice_core.speak($"done");
     }
     Thread.Sleep(60 * 1000); // wait for page to change
 }
Exemplo n.º 8
0
 // add new instagram user just by username
 public bool AddInstaUser(InstaUser IU)
 {
     try
     {
         using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
         {
             // C_voice_core.speak("db AddInstaUser");
             // only add if not already there
             using (SQLiteCommand SQLcommand = new SQLiteCommand("insert into insta_users (username, date_created,date_last_updated) select @username, @datetime, @date_last_updated " +
                                                                 "WHERE NOT EXISTS(SELECT 1 FROM insta_users WHERE username = @username);", _conn))
             {
                 SQLcommand.Parameters.AddWithValue("username", IU.username);
                 SQLcommand.Parameters.AddWithValue("datetime", DateTime.Now.ToString(SQLiteDateTimeFormat));
                 SQLcommand.Parameters.AddWithValue("date_last_updated", DateTime.Now.ToString(SQLiteDateTimeFormat));
                 if (_conn.State != System.Data.ConnectionState.Open)
                 {
                     _conn.Open();
                 }
                 SQLcommand.ExecuteNonQuery();
                 _conn.Close();
             }
         }
     }
     catch (InvalidOperationException se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         IU.error = se.Message;
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     catch (Exception se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         IU.error = se.Message;
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     return(true);
 }
Exemplo n.º 9
0
 public string GetConfigValueFor(string name)
 {
     C_voice_core.speak("database GetConfigValueFor");
     try
     {
         using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
         {
             using (SQLiteCommand SQLcommand = new SQLiteCommand("select value from config WHERE name=@name limit 1;", _conn))
             {
                 SQLcommand.Parameters.AddWithValue("name", name);
                 if (_conn.State != System.Data.ConnectionState.Open)
                 {
                     _conn.Open();
                 }
                 using (SQLiteDataReader rdr = SQLcommand.ExecuteReader())
                 {
                     if (rdr.Read()) // there can only ever be 1 row
                     {
                         return(rdr["value"].ToString());
                     }
                 }
             }
         }
     }
     catch (InvalidOperationException se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     catch (Exception se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
     return(null);
 }
Exemplo n.º 10
0
 //upserts a config value
 public void SetConfigValueFor(string name, string value)
 {
     C_voice_core.speak("database SetConfigValueFor");
     try
     {
         using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
         {
             using (SQLiteCommand SQLcommand = new SQLiteCommand("insert into config (name, value, date_created) select @name, @value, @date " +
                                                                 "where not exists (select 1 from config where name=@name); " +
                                                                 "update config set value = @value, date_changed = @date where name=@name and value != @value; ", _conn))
             {
                 SQLcommand.Parameters.AddWithValue("name", name);
                 SQLcommand.Parameters.AddWithValue("date", DateTime.Now.ToString(SQLiteDateTimeFormat));
                 if (string.IsNullOrEmpty(value))
                 {
                     SQLcommand.Parameters.AddWithValue("value", DBNull.Value);
                 }
                 else
                 {
                     SQLcommand.Parameters.AddWithValue("value", value);
                 }
                 if (_conn.State != System.Data.ConnectionState.Open)
                 {
                     _conn.Open();
                 }
                 SQLcommand.ExecuteNonQuery();
                 _conn.Close();
             }
         }
     }
     catch (InvalidOperationException se)
     {
         C_voice_core.speak($"SQL Error: {se.Message}");
         System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
     }
 }
Exemplo n.º 11
0
        public DateTime BulkFollowBack(bool enableVoices, int banLength, DateTime followingBannedUntil)
        {
            // go to activity page and follow back anyone that followed us
            var minutesLeft = (followingBannedUntil - DateTime.Now).Minutes;
            var secondsLeft = (followingBannedUntil - DateTime.Now).Seconds;

            if (secondsLeft > 0)
            {
                if (minutesLeft == 0) // must be a few seconds left
                {
                    if (enableVoices)
                    {
                        C_voice_core.speak($"follow ban in place for {secondsLeft} more seconds");
                    }
                }
                else
                {
                    if (enableVoices)
                    {
                        C_voice_core.speak($"follow ban in place for {minutesLeft} more minute{(minutesLeft > 1 ? "s" : "")}");
                    }
                }
            }
            else
            {
                _IwebDriver.Navigate().GoToUrl($"https://www.instagram.com/accounts/activity/");
                Thread.Sleep(2 * 1000);
                foreach (var obj in _IwebDriver.FindElements(By.TagName("button")))
                {
                    if (obj.Text.ToLower().Trim().Contains("follow"))
                    {
                        try
                        {
                            obj.Click();
                            Thread.Sleep(2 * 1000);
                            // if following failed dont keep trying
                            if (!obj.Text.ToLower().Trim().Contains("following") && !obj.Text.ToLower().Trim().Contains("requested"))
                            {
                                if (enableVoices)
                                {
                                    C_voice_core.speak($"following failed");
                                }
                                followingBannedUntil = DateTime.Now.AddMinutes(banLength);
                                break;
                            }
                        }
                        catch
                        {
                            if (enableVoices)
                            {
                                C_voice_core.speak($"follow failed error");
                            }
                        }
                    }
                }
            }



            return(followingBannedUntil);
        }
Exemplo n.º 12
0
 public void BulkUnfollow(string username, bool enableVoices, int banLength)
 {
     while (true)
     {
         _IwebDriver.Navigate().GoToUrl($"https://www.instagram.com/{username}");
         Thread.Sleep(2 * 1000); // wait a amount of time for page to change
         foreach (var obj in _IwebDriver.FindElements(By.TagName("a")))
         {
             if (obj.GetAttribute("href").Contains("following") && obj.GetAttribute("href").ToLower().Contains(username)) // find the `following` link
             {
                 obj.Click();                                                                                             // bring up follow list
                 Thread.Sleep(1 * 1000);                                                                                  // wait a amount of time for page to change
                 foreach (var _li in _IwebDriver.FindElements(By.TagName("li")))
                 {
                     //if (enableVoices) C_voice_core.speak($"l i found");
                     try
                     {
                         if (!_li.FindElement(By.TagName("button")).Text.ToLower().Trim().Contains("following"))
                         {
                             //if (enableVoices) C_voice_core.speak($"no following button");
                             continue;
                         }
                         else
                         {
                             //if (enableVoices) C_voice_core.speak($"li found");
                             var _unfollow_button = _li.FindElement(By.TagName("button"));
                             if (_unfollow_button.Text.ToLower().Trim().Contains("following"))
                             {
                                 //if (enableVoices) C_voice_core.speak($"following button found");
                                 try
                                 {
                                     // get username
                                     var _insta_user_name = _li.FindElement(By.TagName("a")).GetAttribute("href").Replace("https://www.instagram.com", "").ToLower().Replace("/", "").ToLower().Trim();
                                     if (enableVoices)
                                     {
                                         C_voice_core.speak($"unfollowing {_insta_user_name}");
                                     }
                                     _unfollow_button.Click();
                                     Thread.Sleep(1 * 1000); // wait a short amount of time between clicks
                                     if (_unfollow_button.Text.ToLower().Trim().Contains("following"))
                                     {
                                         if (enableVoices)
                                         {
                                             C_voice_core.speak($"unfollow failed");
                                         }
                                         break;
                                     }
                                     new C_DataLayer().SaveInstaUser(IU: new InstaUser()
                                     {
                                         username = _insta_user_name, date_unfollowed = DateTime.Now
                                     });
                                 }
                                 catch
                                 {
                                     if (enableVoices)
                                     {
                                         C_voice_core.speak($"unfollow failed error");
                                     }
                                 }
                             }
                         }
                     }
                     catch (NoSuchElementException ne)
                     {
                         Debug.Print(ne.Message);
                     }
                 }
                 break;
             }
         }
     }
 }
Exemplo n.º 13
0
        public void LogInToInstagram(string username, string password, bool enableVoices)
        {
            _IwebDriver.Navigate().GoToUrl("https://www.instagram.com/accounts/logout/");
            _IwebDriver.Manage().Cookies.DeleteAllCookies();                                         //logout
            _IwebDriver.Navigate().GoToUrl("https://www.instagram.com/accounts/login/");
            Thread.Sleep(1 * 1000);                                                                  // wait for page to change

            foreach (var button in _IwebDriver.FindElements(By.ClassName("coreSpriteDismissLarge"))) // dismiss cookie policy
            {
                button.Click();
            }

            foreach (var link in _IwebDriver.FindElements(By.Name("a"))) // click switch accounts link
            {
                if (link.GetAttribute("href").Contains("javascript:;"))
                {
                    C_voice_core.speak($"clicking switch user");
                    link.Click();
                }
            }

            // if (enableVoices) c_voice_core.speak($"let's connect to Instagram");
            if (password.Length < 4)
            {
                if (enableVoices)
                {
                    C_voice_core.speak($"You have one minute to complete login");
                }
                Thread.Sleep(60 * 1000); // wait for page to change
            }
            else
            {
                foreach (var link in _IwebDriver.FindElements(By.Name("a"))) // click switch accounts link
                {
                    if (link.GetAttribute("href") == @"javascript:;")
                    {
                        C_voice_core.speak($"clicking switch user");
                        link.Click();
                        Thread.Sleep(1 * 1000); // wait for page to change
                    }
                }
                _IwebDriver.FindElement(By.Name("username")).SendKeys(username);
                _IwebDriver.FindElement(By.Name("password")).SendKeys(password);
                _IwebDriver.FindElement(By.TagName("form")).Submit();
                Thread.Sleep(3 * 1000); // wait for page to change
            }


            if (_IwebDriver.PageSource.Contains("your password was incorrect"))
            {
                if (enableVoices)
                {
                    C_voice_core.speak($"You have one minute to complete login");
                }
                Thread.Sleep(60 * 1000); // wait for page to change
            }
            else if (_IwebDriver.PageSource.Contains("security") || _IwebDriver.PageSource.Contains("Unusual"))
            {
                if (enableVoices)
                {
                    C_voice_core.speak($"You have one minute to complete login");
                }
                Thread.Sleep(60 * 1000); // wait for page to change
            }
            else
            {
                if (enableVoices)
                {
                    C_voice_core.speak($"We are in, awesome");
                }
            }
        }
Exemplo n.º 14
0
        //TODO: create database schema
        private void InitiateDatabase()
        {
            // C_voice_core.speak("db create table insta_users");
            try
            {
                using (SQLiteConnection _conn = new SQLiteConnection(SQLiteConnString, true))
                {
                    // DO NOT ALTER TABLES
                    // create insta_users table
                    using (SQLiteCommand SQLcommand = new SQLiteCommand("CREATE TABLE IF NOT EXISTS " +
                                                                        "insta_users" +
                                                                        "(" +
                                                                        "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                                                                        "username varchar(255) not null," +
                                                                        "date_created TEXT not null," +
                                                                        "date_followed_them TEXT null," +
                                                                        "date_unfollowed_them TEXT null," +
                                                                        "date_followed_back_detected TEXT null," +
                                                                        "date_last_commented TEXT null," +
                                                                        "date_last_liked TEXT null," +
                                                                        "times_followed INTEGER DEFAULT 0," +
                                                                        "times_unfollowed INTEGER DEFAULT 0," +
                                                                        "date_last_updated TEXT not null" +
                                                                        ");", _conn))
                    {
                        if (_conn.State != System.Data.ConnectionState.Open)
                        {
                            _conn.Open();
                        }
                        SQLcommand.ExecuteNonQuery();
                        _conn.Close();
                    }


                    //  C_voice_core.speak("db create table config");
                    // create config table (name / values)
                    using (SQLiteCommand SQLcommand = new SQLiteCommand("CREATE TABLE IF NOT EXISTS " +
                                                                        "config" +
                                                                        "(" +
                                                                        "name varchar(50) PRIMARY KEY not null," +
                                                                        "value varchar(255) not null," +
                                                                        "date_created TEXT not null," +
                                                                        "date_changed TEXT null" +
                                                                        ");", _conn))
                    {
                        if (_conn.State != System.Data.ConnectionState.Open)
                        {
                            _conn.Open();
                        }
                        SQLcommand.ExecuteNonQuery();
                        _conn.Close();
                    }
                    //  C_voice_core.speak("db create table stat_log");
                    // create stat_log
                    using (SQLiteCommand SQLcommand = new SQLiteCommand("CREATE TABLE IF NOT EXISTS " +
                                                                        "stat_log" +
                                                                        "(" +
                                                                        "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                                                                        "followers INTEGER null," +
                                                                        "following INTEGER null," +
                                                                        "posts INTEGER null," +
                                                                        "datetime TEXT not null" +
                                                                        ");", _conn))
                    {
                        if (_conn.State != System.Data.ConnectionState.Open)
                        {
                            _conn.Open();
                        }
                        SQLcommand.ExecuteNonQuery();
                        _conn.Close();
                    }
                }
            }
            catch (InvalidOperationException se)
            {
                C_voice_core.speak($"SQL Error: {se.Message}");
                System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
            }
            catch (Exception se)
            {
                C_voice_core.speak($"SQL Error: {se.Message}");
                System.Windows.Forms.MessageBox.Show($"SQL Error: {se.Message}");
            }
        }
Exemplo n.º 15
0
        public DateTime FollowPostUser(bool enableVoices, int banLength, DateTime followingBannedUntil, string instagram_post_user)
        {
            // FOLLOW
            foreach (var obj in _IwebDriver.FindElements(By.TagName("button")))
            {
                if (obj.Text.ToUpper().Contains("FOLLOWING".ToUpper()))
                {
                    // if (enableVoices) C_voice_core.speak($"already following");
                    break;
                }
                else if (obj.Text.ToUpper().Contains("FOLLOW".ToUpper()) && followingBannedUntil > DateTime.Now)
                {
                    var _minutesLeft = (followingBannedUntil - DateTime.Now).Minutes;
                    var _secondsLeft = (followingBannedUntil - DateTime.Now).Seconds;
                    if (_minutesLeft == 0) // must be a few seconds left
                    {
                        if (enableVoices)
                        {
                            C_voice_core.speak($"follow ban in place for {_secondsLeft} more seconds");
                        }
                    }
                    else
                    {
                        if (enableVoices)
                        {
                            C_voice_core.speak($"follow ban in place for {_minutesLeft} more minute{(_minutesLeft > 1 ? "s" : "")}");
                        }
                    }
                    break;
                }
                else if (obj.Text.ToUpper().Contains("FOLLOW".ToUpper()))
                {
                    if (enableVoices)
                    {
                        C_voice_core.speak($"following");
                    }
                    obj.Click();
                    Thread.Sleep(2 * 1000); // wait and see it it worked, will change to following
                    if (obj.Text.ToUpper().Contains("FOLLOWING".ToUpper()))
                    {
                        // testing new database functionality
                        new Classes.C_DataLayer().SaveInstaUser(IU: new Classes.InstaUser()
                        {
                            username = instagram_post_user.Replace(" ", "_"), date_followed_them = DateTime.Now
                        });
                    }
                    else
                    {
                        followingBannedUntil = DateTime.Now.AddMinutes(banLength);
                        if (enableVoices)
                        {
                            C_voice_core.speak($"follow failed, I will stop following for {banLength} minutes.");
                        }
                    }
                    Thread.Sleep(2 * 1000); // wait and see it it worked, will change to following
                    break;
                }
            }

            return(followingBannedUntil);
            // end FOLLOW
        }
Exemplo n.º 16
0
        public void GetStats(string username, bool enableVoices)
        {
            // start get stats
            if (enableVoices)
            {
                C_voice_core.speak($"ok {user}, let's check your stats");
            }
            // Return to users profile page so they can see their stats while we wait for next search to start
            _IwebDriver.Navigate().GoToUrl($"https://www.instagram.com/{username}");
            //TODO: when testing on a new account with no profile image (may be unrelated) the stats below are not found, need to figure out why. Have increased wait to from 3 to 4 seconds to see if that helps.
            Thread.Sleep(4 * 1000); // wait a amount of time for page to change
            string followers = "";

            foreach (var obj in _IwebDriver.FindElements(By.TagName("a")))
            {
                if (obj.GetAttribute("href").Contains("followers") &&
                    obj.GetAttribute("href").ToLower().Contains(username))
                {
                    followers = obj.FindElement(By.TagName("span")).Text.Replace(",", "").Replace(" ", "").Replace("followers", "");
                    break;
                }
            }
            string following = "";

            foreach (var obj in _IwebDriver.FindElements(By.TagName("a")))
            {
                if (obj.GetAttribute("href").Contains("following") &&
                    obj.GetAttribute("href").ToLower().Contains(username))
                {
                    following = obj.FindElement(By.TagName("span")).Text.Replace(",", "").Replace(" ", "").Replace("following", "");
                    break;
                }
            }

            string posts = "";

            foreach (var obj in _IwebDriver.FindElements(By.TagName("li")))
            {
                if (obj.Text.Contains(" posts"))
                {
                    posts = obj.Text.Replace(",", "").Replace(" ", "").Replace("posts", "");
                    break;
                }
            }


            // check scraped stat/followers/following data is valid
            if (int.TryParse(followers, out int _followers) &&
                int.TryParse(following, out int _following) &&
                int.TryParse(posts, out int _posts)
                )
            {
                // testing new database functionality
                new Classes.C_DataLayer().SaveCurrentStats(followers: _followers, following: _following, posts: _posts);
            }

            if (enableVoices)
            {
                C_voice_core.speak($"You have a total of {posts} posts, {followers} followers and are following {following}. Well done, but I take all the credit.");
            }
            // end get stats
        }
Exemplo n.º 17
0
        public DateTime CommentOnPost(string username, bool enableVoices, int banLength, int secondsBetweenActions_min, int secondsBetweenActions_max, List <string> phrasesToComment, DateTime commentingBannedUntil, string instagram_post_user)
        {
            // START COMMENTING
            // check if we are banned from commenting
            var _commentBanminutesLeft = (commentingBannedUntil - DateTime.Now).Minutes;
            var _commentBanSecondsLeft = (commentingBannedUntil - DateTime.Now).Seconds;

            if (_commentBanSecondsLeft > 0)
            {
                if (_commentBanSecondsLeft == 0) // must be a few seconds left
                {
                    if (enableVoices)
                    {
                        C_voice_core.speak($"comment ban in place for {_commentBanSecondsLeft} more seconds");
                    }
                }
                else
                {
                    if (enableVoices)
                    {
                        C_voice_core.speak($"comment ban in place for {_commentBanminutesLeft} more minute{(_commentBanminutesLeft > 1 ? "s" : "")}");
                    }
                }
            }
            else
            {
                // COMMENT - this is usually the first thing to be blocked if you reduce time delays, you will see "posting fialed" at bottom of screen.
                // pick a random comment
                // {USERNAME} get's replaced with @USERNAME
                // {DAY} get's replaced with today's day .g: MONDAY, TUESDAY etc..
                var myComment = phrasesToComment[new Random().Next(0, phrasesToComment.Count - 1)].Replace("{USERNAME}", "@" + username.Replace("{DAY}", "@" + DateTime.Now.ToString("dddd")));
                // click the comment icon so the comment textarea will work (REQUIRED)
                foreach (var obj in _IwebDriver.FindElements(By.TagName("a")))
                {
                    if (obj.Text.ToUpper().Contains("COMMENT".ToUpper()))
                    {
                        obj.Click();                                                                                  // click comment icon
                        Thread.Sleep(new Random().Next(secondsBetweenActions_min, secondsBetweenActions_max) * 1000); // wait a short(random) amount of time for page to change
                        break;
                    }
                }
                //TODO: posts with comments disabled cause the bot to stall
                // make the comment
                foreach (var obj in _IwebDriver.FindElements(By.TagName("textarea")))
                {
                    if (obj.GetAttribute("placeholder").ToUpper().Contains("COMMENT".ToUpper()))
                    {
                        if (enableVoices)
                        {
                            C_voice_core.speak($"commenting");
                        }
                        bool sendKeysFailed   = true;// must start as true
                        int  attempsToComment = 0;
                        while (sendKeysFailed && attempsToComment < 3)
                        {
                            attempsToComment++;
                            try
                            {
                                obj.SendKeys(myComment); // put comment in textarea
                                break;
                            }
                            catch (Exception e)
                            {
                                if (e.Message.Contains("element not visible"))
                                { // comments disbaled on post, nothing to wory about
                                }
                                else if (e.Message.Contains("character"))
                                {
                                    if (enableVoices)
                                    {
                                        C_voice_core.speak($"The comment {myComment} contains an unsupported character, i'll remove it from the list.");
                                    }
                                    sendKeysFailed = true;              // some characters are not supported by chrome driver (some emojis for example)
                                    phrasesToComment.Remove(myComment); // remove offending comment
                                }
                                else
                                {   // other unknown error, relay full error message but dont remove comment from list as it may be perfectly fine.
                                    if (enableVoices)
                                    {
                                        C_voice_core.speak($"error with a comment, the error was {e.Message}. The comment {myComment} will be removed from the list.");
                                    }
                                    sendKeysFailed = true; // some characters are not supported by chrome driver (some emojis for example)
                                }
                                if (phrasesToComment.Count == 0)
                                {
                                    break;
                                }
                                myComment = phrasesToComment[new Random().Next(0, phrasesToComment.Count - 1)]; // select another comments and try again
                            }
                        }
                        Thread.Sleep(1 * 1000);                               // wait for comment to type
                        _IwebDriver.FindElement(By.TagName("form")).Submit(); // Only one form on page, so submit it to comment.
                        Thread.Sleep(3 * 1000);                               // wait a short(random) amount of time for page to change
                        //TODO: posts with comments disabled cause the bot to stall, moving this here should fix it
                        // check if comment failed, if yes remove that comment from our comments list
                        if (_IwebDriver.PageSource.ToUpper().Contains("couldn't post comment".ToUpper()))
                        {
                            if (enableVoices)
                            {
                                C_voice_core.speak($"comment failed, I will stop commenting for {banLength} minutes.");
                            }
                            commentingBannedUntil = DateTime.Now.AddMinutes(banLength);
                        }
                        else
                        {
                            // commenting worked
                            // testing new database functionality
                            new Classes.C_DataLayer().SaveInstaUser(IU: new Classes.InstaUser()
                            {
                                username = instagram_post_user.Replace(" ", "_"), date_last_commented = DateTime.Now
                            });
                        }
                        break;
                    }
                }
            }
            // END COMMENTING
            return(commentingBannedUntil);
        }