public void StartProcessOfGettingTweetId(object ac) { TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); //TwitterDataScrapper.logEvents.addToLogger += new EventHandler(retweetOfUrl_logEvents_addToLogger); //tweetScrapper.noOfRecords = ((int.Parse(txtCountFavoriteandRetweet.Text.Trim()) * TweetAccountContainer.dictionary_TweetAccount.Count)); try { TwitterDataScrapper.noOfRecords = (int.Parse(txtCountFavoriteandRetweet.Text.Trim())) * TweetAccountContainer.dictionary_TweetAccount.Count; AddToLog_RetweetAndFavorite("[ " + DateTime.Now + " ] => [Getting Tweets For KeyWord " + txt_TweetUrl.Text.Trim() + " ]"); tweetScrapper.NewKeywordStructDataForOnlyTweet(txt_TweetUrl.Text.Trim()); } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine("Error :- Mathod Name :- StartProcessOfGettingTweetId :- " + ex.Message, Globals.path_LogErrorFromRetweetAndFavorit); } }
public void FollowUsingURLs(List<string> list_user_id_toFollow, int minDelay, int maxDelay, bool OtherUser) { int counter = 0; int counterChecktotlaFollowr = 0; try { //Login(); try { DataSet Dataset = new DataSet(); if (NoOfFollowPerDay_ChkBox == true) { Dataset = CheckLimitationOfPerID(Username); if (Dataset != null) { if (Dataset.Tables.Count != 0) { if (Dataset.Tables[0].Rows.Count != 0) { Log("[ " + DateTime.Now + " ] => [ No Of Follow Per Day - " + NoOfFollowPerDay + " ]"); int DataSetTableRowsCount = Dataset.Tables[0].Rows.Count; RemainingNoOfFollowPerDay = NoOfFollowPerDay - DataSetTableRowsCount; } else { RemainingNoOfFollowPerDay = NoOfFollowPerDay; } } else { RemainingNoOfFollowPerDay = NoOfFollowPerDay; } } } else { RemainingNoOfFollowPerDay = TweetAccountManager.NoOfFollowPerDay; } } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- NoOfFollowPerDay_ChkBox --> " + ex.Message, Globals.Path_FollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- FollowUsingURLs() -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } ///Login if Not Logged in if (!IsLoggedIn) { Login(); } ///Return if Suspended if (AccountStatus == "Account Suspended") { Log("[ " + DateTime.Now + " ] => [ " + Username + " : Suspended ]"); return; } if (IsLoggedIn) { #region trial last tweet date code //if (UseDateLastTweeted) //{ // string PageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + Screen_name), "", ""); // string[] Array = Regex.Split(PageSource, "href="); // foreach (string item in Array) // { // if (item.Contains(Screen_name + "/status/") && item.Contains("tweet-timestamp js-permalink js-nav")) // { // try // { // int startIndex = item.IndexOf("title=\""); // string Start = item.Substring(startIndex).Replace("title=\"", ""); // int endIndex = Start.IndexOf("\" >"); // string End = Start.Substring(0, endIndex); // string[] array = Regex.Split(End, " "); // DateTime lastTweetDate = new DateTime(Convert.ToInt32(array[5]), 08, Convert.ToInt32(array[3]), 12, 12, 12); // DateTime dt_Now = DateTime.Now; // TimeSpan dt_Difference = lastTweetDate.Subtract(dt_Now); // TimeSpan t = dt_Now - lastTweetDate; // double NrOfDays = t.TotalDays; // if (dt_Difference.Days >= LastTweetDays) // { // Log("Not Followed as Last Tweeted Day is greated than specified For : " + Username); // continue; // } // } // catch (Exception ex) // { // } // } // } //} #endregion int NoOfFollowCounter = 0; clsDBQueryManager queryManager = new clsDBQueryManager(); TwitterDataScrapper dataScrapper = new TwitterDataScrapper(); ///Get list of Already Followings List<string> lst_AlreadyUserid = new List<string>(); ; List<string> lst_AlreadyUserName = new List<string>(); if (list_user_id_toFollow.Count > 0 && !string.IsNullOrEmpty(list_user_id_toFollow[0])) { foreach (string user_id_toFollow in list_user_id_toFollow) { if (NoOfFollowPerDay_ChkBox) { if (NoOfFollowCounter >= RemainingNoOfFollowPerDay) { Log("[ " + DateTime.Now + " ] => [ Finish Follow Limit " + NoOfFollowPerDay + " Today ]"); break; } } string followStatus; string user_id = string.Empty; string pagesource = string.Empty; string Screen_name = string.Empty; ///Getting Username from User id ///Working from both username n id clsDBQueryManager DB = new clsDBQueryManager(); #region commented for choosing username and userid //if (!GlobusRegex.ValidateNumber(user_id_toFollow))//(!IsItNumber(user_id_toFollow)) //if (frmMain_NewUI.IsFollowerScreanName) //{ // DataSet ds = DB.GetUserId(user_id_toFollow); // if (ds.Tables.Count != 0 && ds.Tables[0].Rows.Count > 0) // { // foreach (DataRow dataRow in ds.Tables["tb_UsernameDetails"].Rows) // { // user_id = dataRow.ItemArray[0].ToString(); // } // } //} //else if (frmMain_NewUI.IsfollowerUserId) //{ // user_id = user_id_toFollow; // DataSet ds = DB.GetUserName(user_id_toFollow); // if (ds.Tables[0].Rows.Count > 0) // { // foreach (DataRow dataRow in ds.Tables["tb_UsernameDetails"].Rows) // { // user_id = dataRow.ItemArray[0].ToString(); // } // } //} //else //{ // user_id = string.Empty; // Log("Please enter Valid user Id Or Screan name. "); //} #endregion #region get check unfollow befor if (TweetAccountManager.UseUnfollowedBeforeFilter) { List<string> lst_AlreadyExist = new List<string>(); if (frmMain_NewUI.IsFollowerScreenName) { lst_AlreadyExist = DB.SelectUnFollowDUsernameID_List(Username); bool isAlreadyExist = lst_AlreadyExist.Exists(s => (s == user_id_toFollow)); if (isAlreadyExist) { Log("[ " + DateTime.Now + " ] => [ " + user_id_toFollow + " Is already Unfollowed before from " + Username + " ]"); continue; } } else if (frmMain_NewUI.IsfollowerUserId && BaseLib.NumberHelper.ValidateNumber(user_id_toFollow)) { lst_AlreadyExist = DB.SelectUnFollowedUsername_List(Username); bool isAlreadyExist = lst_AlreadyExist.Exists(s => (s == user_id_toFollow)); if (isAlreadyExist) { Log("[ " + DateTime.Now + " ] => [ " + user_id_toFollow + " Is already Unfollowed before from " + Username + " ]"); continue; } } } #endregion ///Counter For Follow NoOfFollowCounter++; //Check if user_id_toFollow is already being followed or not #region user_id_toFollow is already being followed or not bool isAlreadyFollowed = false; Log("[ " + DateTime.Now + " ] => [ Checking For Already Followed For " + user_id_toFollow + " From " + Username + " ]"); if (frmMain_NewUI.IsFollowerScreenName) { lst_AlreadyUserName = queryManager.SelectFollowDUsername_List(Username); isAlreadyFollowed = lst_AlreadyUserName.Exists(s => (s == user_id_toFollow)); Screen_name = user_id_toFollow; } else if (frmMain_NewUI.IsfollowerUserId && BaseLib.NumberHelper.ValidateNumber(user_id_toFollow)) { lst_AlreadyUserid = queryManager.SelectFollowDUsernameID_List(Username); isAlreadyFollowed = lst_AlreadyUserid.Exists(s => (s == user_id_toFollow)); user_id = user_id_toFollow; } else { Log("[ " + DateTime.Now + " ] => [ UserId/ScreenName Not In Correct Format :- " + user_id_toFollow + " ]"); return; } #endregion if (!isAlreadyFollowed) //If not already being followed, follow now { ///Use FollowingsFollowers Ratio Filter if (UseRatioFilter) { int FollowingsFollowersRatio_user_id = 0; //Check FollowingsFollowers Ratio of this user_id try { string returnstatusFollower = string.Empty; string returnstatusFollowing = string.Empty; List<string> Following = dataScrapper.GetFollowings(user_id, out returnstatusFollowing); List<string> Follower = dataScrapper.GetFollowers(user_id, out returnstatusFollower); int count_Followings_user_id = Following.Count; int count_Followers_user_id = Follower.Count; FollowingsFollowersRatio_user_id = (count_Followings_user_id * 100) / count_Followers_user_id; } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingURLs() -- UseRatioFilter --> " + ex.Message, Globals.Path_FollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- FollowUsingURLs() -- UseRatioFilter -- " + Username + " -- " + user_id_toFollow + " --> " + ex.Message, Globals.Path_TweetAccountManager); } if (!(FollowingsFollowersRatio_user_id >= FollowingsFollowersRatio)) //If FollowingsFollowersRatio_user_id is less than Required, continue with next user_id_toFollow { Log("[ " + DateTime.Now + " ] => [ Not Followed as FollowingsFollowersRatio : " + FollowingsFollowersRatio_user_id + " for " + user_id_toFollow + " with : " + Username + " ]"); continue; } } #region Old Unfollowed Before Code //if (UseUnfollowedBeforeFilter) //{ // try // { // List<string> lst_Followings_Current = dataScrapper.GetFollowings(user_id); // //lst_AlreadyFollowings // } // catch { } //} #endregion #region Old Tweet Last Day Code if (UseDateLastTweeted && !string.IsNullOrEmpty(user_id)) { try { string strLastTweetDate = dataScrapper.GetUserLastTweetDate(user_id); DateTime dt_LastTweetDate = DateTime.Parse(strLastTweetDate); DateTime dt_Now = DateTime.Now; TimeSpan dt_Difference = dt_Now.Subtract(dt_LastTweetDate); if (dt_Difference.Days >= LastTweetDays) { Log("[ " + DateTime.Now + " ] => [ Not Followed as Last Tweeted Day is greated than specified for :" + user_id_toFollow + " with : " + Username + " ]"); continue; } } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingURLs() -- Last Tweeted --> " + ex.Message, Globals.Path_FollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- FollowUsingURLs() -- UseDateLastTweeted -- " + Username + " -- " + user_id_toFollow + " --> " + ex.Message, Globals.Path_TweetAccountManager); } } #endregion #region Check Profile Picture if (IscontainPicture) { Log("[ " + DateTime.Now + " ] => [ Checking Profile Image For : " + user_id_toFollow + " ]"); string containsIamge = TwitterDataScrapper.GetPhotoFromUsername_New(Screen_name); Thread.Sleep(1000); if (containsIamge == "true") { Log("[ " + DateTime.Now + " ] => [ " + user_id_toFollow + " Contains Image ]"); } else if (containsIamge == "false") { Log("[ " + DateTime.Now + " ] => [ " + user_id_toFollow + " Not Contains Image So Not Following ]"); continue; } else if (containsIamge == "Rate limit exceeded") { Log("[ " + DateTime.Now + " ] => [ Cannot Make Request. Rate limit exceeded ]"); Log("[ " + DateTime.Now + " ] => [ Please Try After Some Time ]"); Thread.Sleep(5000); } } #endregion #region Checking Tweet in the last xx days. if (IsTweetedInXdays) { Log("[ " + DateTime.Now + " ] => [checking tweeted in the last " + daysTweetedInxdays + " days for User :"******" ]"); try { string PageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + user_id_toFollow), "", ""); string dateoflastTweet = globusHttpHelper.getBetween(PageSource, "ProfileTweet-timestamp js-permalink js-nav js-tooltip", ">").Replace("\"","").Trim(); try { dateoflastTweet = dateoflastTweet.Split('-')[1].Trim(); DateTime dt_LastTweetDate = DateTime.Parse(dateoflastTweet); DateTime dt_Now = DateTime.Now; TimeSpan dt_Difference = dt_Now.Subtract(dt_LastTweetDate); if (dt_Difference.Days >= Convert.ToInt32(daysTweetedInxdays)) { Log("[ " + DateTime.Now + " ] => [ Not Followed as Last Tweeted Day is greated than specified for :" + user_id_toFollow + " with : " + Username + " ]"); continue; } } catch { } } catch (Exception ex) { } } #endregion int delay = 10 * 1000; int delay1 = 10 * 1000; try { if (Globals.IsGlobalDelay && Globals.IsCheckValueOfDelay) { if (Globals.FollowerRunningText == "FollowerModule" && Globals.TweetRunningText == "TweetModule") { delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay); delay1 = RandomNumberGenerator.GenerateRandom(Globals.MinGlobalDelay, Globals.MaxGlobalDelay); } else { delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay); } } else { delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay); } } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingURLs() -- delay --> " + ex.Message, Globals.Path_FollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- FollowUsingURLs() -- delay -- " + Username + " -- " + user_id_toFollow + " --> " + ex.Message, Globals.Path_TweetAccountManager); } if (Globals.IsCampaign) { lock (locker_que_Follower) { if (string.IsNullOrEmpty(user_id)) { try { string PageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + user_id), "", ""); int startindex = PageSource.IndexOf("data-user-id=\""); string start = PageSource.Substring(startindex).Replace("data-user-id=\"", ""); int endindex = start.IndexOf("\""); string end = start.Substring(0, endindex); user_id = end; } catch (Exception ex) { } } if (string.IsNullOrEmpty(Screen_name)) { try { string PageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/account/redirect_by_id?id=" + user_id), "", ""); int startindex = PageSource.IndexOf("user-style-"); string start = PageSource.Substring(startindex).Replace("user-style-", ""); int endindex = start.IndexOf("\""); string end = start.Substring(0, endindex); Screen_name = end; } catch (Exception ex) { } } string strQuery = "Select * from tb_CampaignReport Where Follower = '" + user_id + "' OR ScreenName = '" + Screen_name + "' AND Campaign_Name = '" + Globals.Campaign_Name + "' "; DataSet ds = DataBaseHandler.SelectQuery(strQuery, "tb_CampaignReport"); if (ds.Tables[0].Rows.Count > 0 && Globals.IsCampaign) { Log("[ " + DateTime.Now + " ] => [ Already Followed Userid : " + user_id + " >>>> ScreenName : " + Screen_name + " ]"); } else { follower.FollowUsingProfileID_New(ref globusHttpHelper, pgSrc_Profile, postAuthenticityToken, user_id_toFollow, out followStatus); string Screen_Name = string.Empty; string userid = string.Empty; if (NumberHelper.ValidateNumber(user_id)) { userid = user_id; } else { Screen_name = user_id; } Log("[ " + DateTime.Now + " ] => [ Followed Userid : " + user_id + " >>>> ScreenName : " + Screen_name + " ]"); Log("[ " + DateTime.Now + " ] => [ Adding Follower in DataBase ]"); string query = "INSERT INTO tb_CampaignReport (Campaign_Name, UserName, Follower , ScreenName) VALUES ('" + Globals.Campaign_Name + "', '" + Username + "', '" + user_id + "' , '" + Screen_name + "')"; DataBaseHandler.InsertQuery(query, "tb_CampaignReport"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + user_id + ":" + Screen_name + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_SuccessfullyFollowAccounts); } } } else { follower.FollowUsingProfileID_New(ref globusHttpHelper, pgSrc_Profile, postAuthenticityToken, user_id_toFollow, out followStatus); if (followStatus == "followed") { Globals.totalcountFollower++; counterChecktotlaFollowr++; Log("[ " + DateTime.Now + " ] => [ >> Followed >> " + user_id_toFollow + " by " + Username + " ]"); //Adding in text File FOr SuccessFull Paths GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + user_id_toFollow + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_SuccessfullyFollowAccounts); try { string username = string.Empty; string userid = string.Empty; if (NumberHelper.ValidateNumber(user_id_toFollow)) { username = TwitterSignup.TwitterSignup_TwitterDataScrapper.GetUserNameFromUserId(user_id_toFollow); userid = user_id_toFollow; } else { string outStatus = string.Empty; userid = TwitterSignup.TwitterSignup_TwitterDataScrapper.GetUserIDFromUsername(user_id_toFollow, out outStatus); username = user_id_toFollow; } queryManager.InsertUpdateFollowTable(Username, userid, username); } catch (Exception) { } try { RemoveFollwerFromTxtFile(FileFollowUrlPath, user_id_toFollow); } catch { } } else if (followStatus == "Already Followed") { Globals.totalcountFollower++; Log("[ " + DateTime.Now + " ] => [ >> Already Followed >> " + user_id_toFollow + " by " + Username + " ]"); try { RemoveFollwerFromTxtFile(FileFollowUrlPath, user_id_toFollow); } catch { } } else { Log("[ " + DateTime.Now + " ] => [ >> Couldn't Follow >> " + user_id_toFollow + " by " + Username + " ]"); //Adding in text File for Failed Followed Paths GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + user_id + ":" + Screen_name + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedToFollowAccounts); } //if user is check fast follow option then delay is not working on that condition ...!! if (!frmMain_NewUI.IsFastfollow) { if (Globals.IsGlobalDelay && Globals.IsCheckValueOfDelay) { if (Globals.FollowerRunningText == "FollowerModule" && Globals.TweetRunningText == "TweetModule") { //delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay); Log("[ " + DateTime.Now + " ] => [ Follow Delayed for " + delay + " Seconds ]"); Thread.Sleep(delay * 1000); //delay1 = RandomNumberGenerator.GenerateRandom(Globals.MinGlobalDelay, Globals.MaxGlobalDelay); Log("[ " + DateTime.Now + " ] => [ Follow Global Delayed for " + delay1 + " Seconds ]"); Thread.Sleep(delay1 * 1000); } else { Log("[ " + DateTime.Now + " ] => [ Follow Delayed for " + delay + " Seconds ]"); Thread.Sleep(delay * 1000); } } else { Log("[ " + DateTime.Now + " ] => [ Follow Delayed for " + delay + " Seconds ]"); Thread.Sleep(delay * 1000); } } if (OtherUser) { counter++; if (counter == noOFFollows) { break; } } } } else //Already Being Followed { Log("[ " + DateTime.Now + " ] => [ Already Followed : " + user_id_toFollow + " with : " + Username + " ]"); try { RemoveFollwerFromTxtFile(FileFollowUrlPath, user_id_toFollow); } catch { } } } } else { Log("[ " + DateTime.Now + " ] => [ Sorry No User To Follow"); return; } } else { Log("[ " + DateTime.Now + " ] => [ >> Couldn't Login with>> " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedLoginAccounts); } } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingURLs() --> " + ex.Message, Globals.Path_FollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- FollowUsingURLs() -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } finally { Log("[ " + DateTime.Now + " ] => [ Finished Following All Users For Username : "******" ]"); Log("------------------------------------------------------------------------------------------------------------------------------------------"); GlobusFileHelper.AppendStringToTextfileNewLine("Module Follow count : " + counterChecktotlaFollowr + " using UserName: " + Username, Globals.path_CountNoOfProcessDone); } }
public void static_lst_Struct_TweetDataMethod() { while (true) { //try //{ // List<Thread> threadList = ThreadpoolMethod_RetweetThreads; // foreach (Thread tr in threadList) // { // try // { // tr.Suspend(); // } // catch { }; // } //} //catch{}; TweetAccountManager.static_lst_Struct_TweetData.Clear(); List<string> twtKeyword = GlobusFileHelper.ReadFiletoStringList(txtTweetKeyword.Text); TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); List<TwitterDataScrapper.StructTweetIDs> strList; foreach (string keyword in twtKeyword) { try { strList = tweetScrapper.TweetExtractor_ByUserName_New_New(keyword); TweetAccountManager.static_lst_Struct_TweetData.Add(strList[0]); } catch { }; } //try //{ // List<Thread> threadList = ThreadpoolMethod_RetweetThreads; // foreach (Thread tr in threadList) // { // try // { // tr.Resume(); // } // catch { }; // } //} //catch { }; AddToLog_Tweet("[ " + DateTime.Now + " ] => No of Retweets Found From All Keyword : " + TweetAccountManager.static_lst_Struct_TweetData.Count); AddToLog_Tweet("[ " + DateTime.Now + " ] => searching for new tweet,process will start again after 2 minute"); Thread.Sleep(2 * 60 * 1000); } }
public List<string> GetFollowings(ref GlobusHttpHelper Httphelper) { TwitterDataScrapper followingScrapper = new TwitterDataScrapper(); followingScrapper.CounterDataNo = noOfUnfollows; string returnStatus = string.Empty; //list_Followings = followingScrapper.GetFollowings_New(Screen_name, out returnStatus, ref Httphelper);//GetFollowings_NewForUnfollower list_Followings = followingScrapper.GetFollowings_NewForUnfollower(Screen_name, out returnStatus, ref Httphelper); return list_Followings; }
public void Reply(string tweetMessage, int minDelay, int maxDelay) { //Login(); List<string> lstTemp = new List<string>(); //if (true) try { TwitterDataScrapper.StructTweetIDs TweeetData = new TwitterDataScrapper.StructTweetIDs(); if (!IsLoggedIn) { Login(); } if (IsNotSuspended) { if (IsLoggedIn) { int counter_Reply = 0; //foreach (TwitterDataScrapper.StructTweetIDs item in static_lst_Struct_TweetData) //{ // List_of_struct_Keydatafrom_tweetData_list.Enqueue(item); //TweeetData = List_of_struct_Keydatafrom_tweetData_list.Dequeue(); while (que_ReplyMessages.Count > 0) { int delay = 10 * 1000; int counter = 0; try { delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay); } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()-- delay --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- Reply() -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } // Code for Sending unique Reply // By Puja lock (locker_que_ReplyTweetMessage) { //if (IsreplyUniqueTweet) { if (que_ReplyMessages.Count > 0) { try { tweetMessage = que_ReplyMessages.Dequeue(); } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()-- locker_que_ReplyTweetMessage --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- Reply()-- locker_que_ReplyTweetMessage -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } } else { Log("[ " + DateTime.Now + " ] => [ All Loaded Tweet Messages Used ]"); //break; } } //Code by Puja #region Code for Reply Per Tweet //if (IsReplyPerTweet) //{ // if (lstTemp.Count == 0) // { // foreach (string item in que_ReplyMessages) // { // lstTemp.Add(item); // } // } // if (counter > lstTemp.Count - 1) // { // counter = 0; // } // tweetMessage = lstTemp[counter]; // counter++; //} #endregion } lock (locker_que_keywyordStructData) { if (List_of_struct_Keydatafrom_tweetData_list.Count > 0) { try { TweeetData = List_of_struct_Keydatafrom_tweetData_list.Dequeue(); } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()-- locker_que_ReplyTweetMessage --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- Reply()-- locker_que_ReplyTweetMessage -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } } else { TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.GetTweetData(ReplyKeyword); foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData) { TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Enqueue(item); } TweeetData = List_of_struct_Keydatafrom_tweetData_list.Dequeue(); } } if (!ReplyPerDay) { if (counter_Reply >= noOfRetweets) { Log("[ " + DateTime.Now + " ] => [ Finished Replying with : " + Username + " ]"); Log("------------------------------------------------------------------------------------------------------------------------------------------"); break; } } else if (ReplyPerDay) { if (AlreadyReply >= NoOFReplyPerDay) { Log("[ " + DateTime.Now + " ] => [ Already Replied " + AlreadyReply + " ]"); break; } } //if (counter_Reply >= noOfRetweets) //{ // //Log("Finished Replying with : " + Username); // break; //} string tweetStatus; tweeter.Reply(ref globusHttpHelper, pgSrc_Profile, postAuthenticityToken, TweeetData.ID_Tweet, TweeetData.username__Tweet_User, tweetMessage, out tweetStatus); if (tweetStatus == "posted") { counter_Reply++; AlreadyReply++; clsDBQueryManager DataBase = new clsDBQueryManager(); string dbTweetMessage = string.Empty; try { dbTweetMessage = StringEncoderDecoder.Encode(TweeetData.wholeTweetMessage); } catch { } DataBase.InsertMessageData(Username, "Reply", TweeetData.ID_Tweet_User, dbTweetMessage); Log("[ " + DateTime.Now + " ] => [ >> Replied : " + counter_Reply + " : " + tweetMessage + " by " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine( tweetMessage + " by " + Username, Globals.path_ReplyInformation); } else { Log("[ " + DateTime.Now + " ] => [ >>Couldn't Reply >> " + tweetMessage + " by " + Username + " ]"); //GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedToFollowAccounts); } Log("[ " + DateTime.Now + " ] => [ Reply Delayed for " + delay + " Seconds ]"); Thread.Sleep(delay * 1000); if (ReplyPerDay) { if (AlreadyReply >= NoOFReplyPerDay) { Log("[ " + DateTime.Now + " ] => [ Finished Replying with : " + Username + " ]"); Log("------------------------------------------------------------------------------------------------------------------------------------------"); break; } } else if (que_ReplyMessages.Count <= 0) { Log("[ " + DateTime.Now + " ] => [ Finished Replying with : " + Username + " ]"); Log("------------------------------------------------------------------------------------------------------------------------------------------"); break; } } //Log("Finished Replying with : " + Username); } else { Log("[ " + DateTime.Now + " ] => [ Couldn't log in with " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedLoginAccounts); } } else { Log("[ " + DateTime.Now + " ] => [ " + Username + ">> Account Suspended ]"); } } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply() --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- Reply() -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } }
private void btnStartReTweeting_Click(object sender, EventArgs e) { CheckNetConn = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); if (chkRetweetDivideTweets.Checked) { TweetAccountManager.IsRetweetDivideRetweet = true; } else { TweetAccountManager.IsRetweetDivideRetweet = false; } List<TwitterDataScrapper.StructTweetIDs> static_lst_Struct_TweetDataTemp = new List<TwitterDataScrapper.StructTweetIDs>(); list_lstTargetTweet = new List<List<TwitterDataScrapper.StructTweetIDs>>(); if (CheckNetConn) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Starting ReTweeting ]"); if (chkboxReplyPerDay.Checked) { MessageBox.Show("Please Check Retweet Per Day Of No Of Retweet"); return; } RetweetExtractCount = Convert.ToInt32(txtNoOfRetweets.Text); TwitterDataScrapper.RetweetExtractcount = RetweetExtractCount; if (!string.IsNullOrEmpty(txtTweetKeyword.Text)) { string tweetKeyword = txtTweetKeyword.Text; if (TweetAccountContainer.dictionary_TweetAccount.Count <= 0) { MessageBox.Show("Please Upload Twitter Accounts to Start ReTweet Feature"); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Please Upload Twitter Accounts to Start ReTweet Feature ]"); return; } if (chk_retweetbyUser.Checked) { new Thread(() => { AddThreadToDictionary(strModule(Module.Retweet), "GettingRetweetsByUsername"); try { Thread.CurrentThread.Name = "ReTweet_GettingRetweetsByUsername"; Thread.CurrentThread.IsBackground = true; dictionary_Threads.Add("ReTweet_GettingRetweetsByUsername", Thread.CurrentThread); } catch { } //get All tweets from entered user name //Scrap Tweets using Username TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); TweetAccountManager.static_lst_Struct_TweetData = new List<TwitterDataScrapper.StructTweetIDs>(); //tweetScrapper.logEvents.addToLogger += new EventHandler(); tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); if (chkCheckDatabaseInEvery2Minutes.Checked == true || chkAutoFavorite.Checked == true || chkRetweetDivideTweets.Checked) { TwitterDataScrapper.noOfRecords = (int.Parse(txtNoOfRetweets.Text)); } else { TwitterDataScrapper.noOfRecords = (int.Parse(txtNoOfRetweets.Text) * TweetAccountContainer.dictionary_TweetAccount.Count); } //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New(tweetKeyword); //tweetScrapper.logEvents.addToLogger -= new EventHandler(logEvents_Tweet_addToLogger); tweetScrapper.RetweetFromUserName = true; foreach (string _ReplyKeywordTemp in lstKeywordRetweetUpload) { static_lst_Struct_TweetDataTemp = tweetScrapper.TweetExtractor_ByUserName_New_New(_ReplyKeywordTemp); TweetAccountManager.static_lst_Struct_TweetData.AddRange(static_lst_Struct_TweetDataTemp); } //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New_New(tweetKeyword); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ We found " + TweetAccountManager.static_lst_Struct_TweetData.Count + " records from keyword. ]"); StartReTweeting(); }).Start(); } else { new Thread(() => { { //Scrap Tweets using Keyword AddThreadToDictionary(strModule(Module.Retweet), "GettingRetweetsByKeyword"); try { Thread.CurrentThread.Name = "ReTweet_ByKeyword"; Thread.CurrentThread.IsBackground = true; dictionary_Threads.Add("ReTweet_ByKeyword", Thread.CurrentThread); } catch { } TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); if (chkCheckDatabaseInEvery2Minutes.Checked == true || chkAutoFavorite.Checked == true) { TwitterDataScrapper.noOfRecords = (int.Parse(txtNoOfRetweets.Text)); } else { TwitterDataScrapper.noOfRecords = (int.Parse(txtNoOfRetweets.Text) * TweetAccountContainer.dictionary_TweetAccount.Count); } //tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); TweetAccountManager.static_lst_Struct_TweetData = new List<TwitterDataScrapper.StructTweetIDs>(); //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.GetTweetData_New1(tweetKeyword); //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.NewKeywordStructData(tweetKeyword); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Please wait we are fetching the tweet data. ]"); //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.NewKeywordStructData(tweetKeyword); foreach (string _ReplyKeywordTemp in lstKeywordRetweetUpload) { static_lst_Struct_TweetDataTemp = tweetScrapper.NewKeywordStructData1(_ReplyKeywordTemp); TweetAccountManager.static_lst_Struct_TweetData.AddRange(static_lst_Struct_TweetDataTemp); } //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.NewKeywordStructData1(tweetKeyword); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ We found " + TweetAccountManager.static_lst_Struct_TweetData.Count + " records from keyword. ]"); tweetScrapper.logEvents.addToLogger -= new EventHandler(logEvents_Tweet_addToLogger); StartReTweeting(); } }).Start(); } } else { MessageBox.Show("Please enter Tweet Search Keyword"); } } else { MessageBox.Show("Your Internet Connection is disabled ! or not working, Please Check Your Internet Connection..."); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Your Internet Connection is disabled ! or not working, Please Check Your Internet Connection... ]"); } }
private void ScrapeMemberSeacrh() { try { lstIsStopScrapMember.Add(Thread.CurrentThread); lstIsStopScrapMember.Distinct(); Thread.CurrentThread.IsBackground = true; } catch { } try { TwitterDataScrapper TweetData = new TwitterDataScrapper(); GlobusHttpHelper globusHttpHelper = new GlobusHttpHelper(); int counter = 0; TweetAccountManager TweetLogin = new TweetAccountManager(); txtlimitScrapeUsers.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txtlimitScrapeUsers.Text.Trim()) && NumberHelper.ValidateNumber(txtlimitScrapeUsers.Text.Trim())) { noOfRecords = Convert.ToInt32(txtlimitScrapeUsers.Text.Trim()); if (noOfRecords == 0) { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Do not put Zero value ]"); AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Default number of records is 50 ]"); noOfRecords = 50; } } else { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ please enter value in number of users ]"); return; } })); foreach (KeyValuePair<string, TweetAccountManager> item in TweetAccountContainer.dictionary_TweetAccount) { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Login process starting]"); if (counter > TweetAccountContainer.dictionary_TweetAccount.Count) { counter = 0; } TweetLogin = new TweetAccountManager(); TweetLogin.Username = item.Key; TweetLogin.Password = item.Value.Password; TweetLogin.IPAddress = item.Value.IPAddress; TweetLogin.IPPort = item.Value.IPPort; TweetLogin.IPUsername = item.Value.IPUsername; TweetLogin.IPpassword = item.Value.IPpassword; TweetLogin.Login(); if (!TweetLogin.IsLoggedIn) { continue; } else { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Login process successful]"); globusHttpHelper = TweetLogin.globusHttpHelper; counter++; break; } } if (!TweetLogin.IsLoggedIn) { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Please Upload Atleast One Working Account To Get Details ]"); return; } AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Scraping User ]"); foreach (string item in lstUrl) { string tempItem = string.Empty; if (!item.Contains("https://twitter.com")) { tempItem = "https://twitter.com" + item; } else { tempItem = item; } List<string> lstMember = new List<string>(); string returnStatus = string.Empty; getTweetUsers(item, ref globusHttpHelper); //lstMember = GetMembers(item, ref globusHttpHelper, out returnStatus); AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Scraped Member for Url " + item + "]"); } } catch { } }
private void threadStartScrape() { TwitterDataScrapper dataScrapeer = new TwitterDataScrapper(); try { List<string> lst_structTweetFollowersIDs = new List<string>(); List<string> lst_structTweetFollowingsIds = new List<string>(); GlobusHttpHelper globusHttpHelper = new GlobusHttpHelper(); string user_id = string.Empty; int counter = 0; TweetAccountManager TweetLogin = new TweetAccountManager(); string ReturnStatus = string.Empty; Globals.IsMobileVersion = true; if (!Globals.IsMobileVersion) { foreach (KeyValuePair<string, TweetAccountManager> item in TweetAccountContainer.dictionary_TweetAccount) { if (counter > TweetAccountContainer.dictionary_TweetAccount.Count) { counter = 0; } TweetLogin = new TweetAccountManager(); TweetLogin.Username = item.Key; TweetLogin.Password = item.Value.Password; TweetLogin.proxyAddress = item.Value.proxyAddress; TweetLogin.proxyPort = item.Value.proxyPort; TweetLogin.proxyUsername = item.Value.proxyUsername; TweetLogin.proxyPassword = item.Value.proxyPassword; TweetLogin.Login(); if (!TweetLogin.IsLoggedIn) { continue; } else { globusHttpHelper = TweetLogin.globusHttpHelper; counter++; break; } } if (!TweetLogin.IsLoggedIn) { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Please Upload Atleast One Working Account To Get Details ]"); return; } } foreach (string keyword in lstscrapeUsername) { dataScrapeer.CounterDataNo = 500; txtlimitScrapeUsers.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txtlimitScrapeUsers.Text) && NumberHelper.ValidateNumber(txtlimitScrapeUsers.Text)) { dataScrapeer.CounterDataNo = Convert.ToInt32(txtlimitScrapeUsers.Text); } })); if (counter > TweetAccountContainer.dictionary_TweetAccount.Count) { counter = 0; } if (chkboxScrapeFollowers.Checked) { try { if (!File.Exists(Globals.Path_ScrapedFollowersList)) { // GlobusFileHelper.AppendStringToTextfileNewLine("Name/Id , FollowersUserID , Followers User Name", Globals.Path_ScrapedFollowersList); GlobusFileHelper.AppendStringToTextfileNewLine("Name/Id , Followers User Name", Globals.Path_ScrapedFollowersList); } try { dataScrapeer.logEvents.addToLogger += new EventHandler(DataScraperlogger_addToLogger); if (!Globals.IsMobileVersion) { lst_structTweetFollowersIDs = dataScrapeer.GetFollowers_New(keyword.Trim(), out ReturnStatus, ref globusHttpHelper); } else { lst_structTweetFollowersIDs = dataScrapeer.GetFollowers_New_ForMobileVersion(keyword.Trim(), out ReturnStatus, ref globusHttpHelper); } dataScrapeer.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); } catch (Exception ex) { } if (lst_structTweetFollowersIDs.Count > 0) { //AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Adding To DataBase and File ]"); //AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowersIDs.Count + " Followers to list ]"); //foreach (string data in lst_structTweetFollowersIDs) //{ // try // { // string[] arr_data = data.Split(':'); // Globals.lstScrapedUserIDs.Add(arr_data[0]); // GlobusFileHelper.AppendStringToTextfileNewLine(keyword + "," + arr_data[0] + "," + arr_data[1], Globals.Path_ScrapedFollowersList); // } // catch (Exception ex) // { // Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> btnScrapeKeyword_Click() -- lst_structTweetFollowersIDs foreach --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); // Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> btnScrapeKeyword_Click() -- lst_structTweetFollowersIDs foreach --> " + ex.Message, Globals.Path_TwtErrorLogs); // } //} AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowersIDs.Count + " Followers from User: "******" ]"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Data Exported to " + Globals.Path_ScrapedFollowersList); if (Globals.IsDirectedFromFollower) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowersIDs.Count + " Followers from User: "******" ]"); Thread.Sleep(1000); } } else if (ReturnStatus.Contains("Sorry, that page does not exist")) { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Sorry, That User does not exist =>" + ReturnStatus.Split(':')[1] + " ]"); continue; } else if (ReturnStatus == "Account is Suspended. ") { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Account " + keyword + " is Suspended. ]"); } else if (ReturnStatus == "Error") { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Rate Limit Exceeded.Please Try After Some Time ]"); } else { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ " + keyword + " User does not exist ]"); } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> btnScrapeUser_Click() -- chkboxScrapeFollowers.Checked --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> btnScrapeUser_Click() -- chkboxScrapeFollowers.Checked --> " + ex.Message, Globals.Path_TwtErrorLogs); } } if (chkboxScrapeFollowings.Checked) { try { if (!File.Exists(Globals.Path_ScrapedFollowingsList)) { // GlobusFileHelper.AppendStringToTextfileNewLine("Name/Id , FollowingsUserID , Following User Name", Globals.Path_ScrapedFollowingsList); GlobusFileHelper.AppendStringToTextfileNewLine("Name/Id , Following User Name", Globals.Path_ScrapedFollowingsList); } string returnStaus = string.Empty; string Screen_name = string.Empty; dataScrapeer.logEvents.addToLogger += new EventHandler(DataScraperlogger_addToLogger); // GlobusHttpHelper globusHttpHelper1 = new GlobusHttpHelper(); if (!Globals.IsMobileVersion) { lst_structTweetFollowingsIds = dataScrapeer.GetFollowings_New(keyword.Trim(), out returnStaus, ref globusHttpHelper); } else { lst_structTweetFollowingsIds = dataScrapeer.GetFollowings_NewForMobileVersion(keyword.Trim(), out returnStaus, ref globusHttpHelper); } if (lst_structTweetFollowingsIds.Count > 0) { if (lst_structTweetFollowingsIds.Count > 0) { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowingsIds.Count + " Followings from User: "******" ]"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Data Exported to " + Globals.Path_ScrapedFollowingsList + " ]"); if (Globals.IsDirectedFromFollower) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowingsIds.Count + " Followings from User: "******" ]"); Thread.Sleep(1000); //Tb_AccountManager.Invoke(new MethodInvoker(delegate //{ // Tb_AccountManager.SelectedIndex = 2; //})); //tabMain.SelectedIndex = 2; } } else if (returnStaus == "Error") { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Rate Limit Exceeded.Please Try After Some Time ]"); break; } } else { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ " + keyword + " User does not have any followings ]"); } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> btnScrapeKeyword_Click() -- lst_structTweetFollowingsIds foreach --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> btnScrapeKeyword_Click() -- lst_structTweetFollowingsIds foreach --> " + ex.Message, Globals.Path_TwtErrorLogs); } } Globals.lstScrapedUserIDs = Globals.lstScrapedUserIDs.Distinct().ToList(); } Globals.IsMobileVersion = false; new Thread(() => { try { List<string> temp = new List<string>(); foreach (string item in Globals.lstScrapedUserIDs) { temp.Add(item); } foreach (string data in temp) { try { clsDBQueryManager DataBase = new clsDBQueryManager(); DataBase.InsertOrUpdateScrapeSetting(data, "", ""); } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> lstScrapedUserIDs --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> lstScrapedUserIDs --> " + ex.Message, Globals.Path_TwtErrorLogs); } } } catch (Exception) { } }).Start(); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]"); AddToScrapeLogs("------------------------------------------------------------------------------------------------------------------------------------------"); //if (IsUserScrapedDatalist) //{ // Tb_AccountManager.Invoke(new MethodInvoker(delegate // { // Tb_AccountManager.SelectedIndex = 0; // //Tb_AccountManager.SelectedTab.Name = "tabFollower"; // })); //} } catch (Exception) { } finally { IsStart_ScrapUser = true; dataScrapeer.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); } }
private void threadStartScrapeInTweetMentionUser() { TwitterDataScrapper dataScrapeer = new TwitterDataScrapper(); try { List<string> lst_structTweetFollowersIDs = new List<string>(); List<string> lst_structTweetFollowingsIds = new List<string>(); GlobusHttpHelper globusHttpHelper = new GlobusHttpHelper(); string user_id = string.Empty; int counter = 0; TweetAccountManager TweetLogin = new TweetAccountManager(); foreach (KeyValuePair<string, TweetAccountManager> item in TweetAccountContainer.dictionary_TweetAccount) { if (counter > TweetAccountContainer.dictionary_TweetAccount.Count) { counter = 0; } TweetLogin = new TweetAccountManager(); TweetLogin.Username = item.Key; TweetLogin.Password = item.Value.Password; TweetLogin.proxyAddress = item.Value.proxyAddress; TweetLogin.proxyPort = item.Value.proxyPort; TweetLogin.proxyUsername = item.Value.proxyUsername; TweetLogin.proxyPassword = item.Value.proxyPassword; AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Logging Process start for scrapping User ]"); TweetLogin.Login(); if (!TweetLogin.IsLoggedIn) { continue; } else { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Logged in successful]"); globusHttpHelper = TweetLogin.globusHttpHelper; counter++; break; } } string ReturnStatus = string.Empty; if (!TweetLogin.IsLoggedIn) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Please Upload Atleast One Working Account To Get Details ]"); return; } //foreach (string keyword in listUserIDs)//foreach (string keyword in lstscrapeUsername) //{ string keyword = txtTweetScrapUserData.Text.Trim(); dataScrapeer.CounterDataNo = 100; listUserIDs.Clear(); txtlimitScrapeUsersINFollower.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txtTweetEnteNoofUser.Text) && NumberHelper.ValidateNumber(txtTweetEnteNoofUser.Text)) { dataScrapeer.CounterDataNo = Convert.ToInt32(txtTweetEnteNoofUser.Text); } })); if (counter > TweetAccountContainer.dictionary_TweetAccount.Count) { counter = 0; } if (chkTweetScrapFollowers.Checked) { try { if (!File.Exists(Globals.Path_ScrapedFollowersList)) { GlobusFileHelper.AppendStringToTextfileNewLine("Name/Id , FollowersUserID , Followers User Name", Globals.Path_ScrapedFollowersList); } string returnStatus = string.Empty; dataScrapeer.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); lst_structTweetFollowersIDs = dataScrapeer.GetFollowers_New(keyword.Trim(), out ReturnStatus, ref globusHttpHelper); dataScrapeer.logEvents.addToLogger -= new EventHandler(logEvents_Tweet_addToLogger); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Followers Scrapped ]"); //TwitterDataScrapper.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); if (lst_structTweetFollowersIDs.Count > 0) { //listUserIDs.Clear(); //string item=Globals.Path_ScrapedFollowersList.Split(':')[0]; //if (Chk_IsFollowerUserId.Checked) { foreach (string item in lst_structTweetFollowersIDs) { string userid = item.Split(':')[1]; lst_mentionUser.Add(userid); } } if (lst_structTweetFollowersIDs.Count > 0) { //listUserIDs.AddRange(lst_structTweetFollowersIDs); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowersIDs.Count + " Followers from User: "******" ]"); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Data Exported to " + Globals.Path_ScrapedFollowersList); } } else if (ReturnStatus.Contains("Sorry, that page does not exist")) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Sorry, That User does not exist =>" + ReturnStatus.Split(':')[1] + " ]"); //continue; } else if (ReturnStatus == "Account is Suspended. ") { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Account " + keyword + " is Suspended. ]"); } else if (ReturnStatus == "Error") { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Rate Limit Exceeded.Please Try After Some Time ]"); } else { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + keyword + " does not have any Followers ]"); } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> btnScrapeUser_Click() -- chkboxScrapeFollowers.Checked --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> btnScrapeUser_Click() -- chkboxScrapeFollowers.Checked --> " + ex.Message, Globals.Path_TwtErrorLogs); } } if (chkRetweetScrapFollowings.Checked) { try { if (!File.Exists(Globals.Path_ScrapedFollowingsList)) { GlobusFileHelper.AppendStringToTextfileNewLine("Name/Id , FollowersUserID , Followers User Name", Globals.Path_ScrapedFollowingsList); } string returnStaus = string.Empty; dataScrapeer.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); lst_structTweetFollowingsIds = dataScrapeer.GetFollowings_New(keyword.Trim(), out returnStaus, ref globusHttpHelper); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Following Scrapped ]"); if (lst_structTweetFollowingsIds.Count > 0) { //listUserIDs.Clear(); //if (Chk_IsFollowerUserId.Checked) { foreach (string item in lst_structTweetFollowingsIds) { string userid = item.Split(':')[1]; lst_mentionUser.Add(userid); } } if (lst_structTweetFollowingsIds.Count > 0) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowingsIds.Count + " Followings from User: "******" ]"); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Data Exported to " + Globals.Path_ScrapedFollowingsList + " ]"); } } else if (ReturnStatus.Contains("Sorry, that page does not exist")) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Sorry, That User does not exist =>" + ReturnStatus.Split(':')[1] + " ]"); //continue; } else if (ReturnStatus == "Account is Suspended. ") { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Account " + keyword + " is Suspended. ]"); } else if (ReturnStatus == "Error") { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Rate Limit Exceeded.Please Try After Some Time ]"); } else { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + keyword + " User does not exist ]"); } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> btnScrapeKeyword_Click() -- lst_structTweetFollowingsIds foreach --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> btnScrapeKeyword_Click() -- lst_structTweetFollowingsIds foreach --> " + ex.Message, Globals.Path_TwtErrorLogs); } } } catch (Exception) { } finally { IsStart_ScrapUser = true; dataScrapeer.logEvents.addToLogger -= new EventHandler(logEvents_Tweet_addToLogger); } }
private void ThreadPoolMethod_Reply(object parameters) { try { Array paramsArray = new object[2]; paramsArray = (Array)parameters; TweetAccountManager keyValue = (TweetAccountManager)paramsArray.GetValue(0); TweetAccountManager tweetAccountManager = keyValue;//keyValue.Value; //try //{ // dictionary_Threads.Add(tweetAccountManager.Username, Thread.CurrentThread); //} //catch { }; //Add to Threads Dictionary AddThreadToDictionary(strModule(Module.Reply), tweetAccountManager.Username); tweetAccountManager.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); //tweetAccountManager.logEvents.addToLogger += logEvents_Tweet_addToLogger; tweetAccountManager.tweeter.logEvents.addToLogger += logEvents_Tweet_addToLogger; if (GlobusRegex.ValidateNumber(txtMinDelay_Tweet.Text)) { replyMinDealy = Convert.ToInt32(txtMinDelay_Tweet.Text); } if (GlobusRegex.ValidateNumber(txtMaxDelay_Tweet.Text)) { replyMaxDealy = Convert.ToInt32(txtMaxDelay_Tweet.Text); } if (chkboxReplyPerDay.Checked) { TweetAccountManager.ReplyPerDay = true; if (!string.IsNullOrEmpty(txtMaximumNoRetweet.Text) && NumberHelper.ValidateNumber(txtMaximumNoRetweet.Text)) { TweetAccountManager.NoOFReplyPerDay = Convert.ToInt32(txtMaximumNoRetweet.Text); } else { TweetAccountManager.NoOFReplyPerDay = 10; AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Adding Default Maximum No Of Retweet 10 ]"); } clsDBQueryManager DbQueryManager = new clsDBQueryManager(); DataSet Ds = DbQueryManager.SelectMessageData(keyValue.Username, "Reply"); int TodayReply = Ds.Tables["tb_MessageRecord"].Rows.Count; tweetAccountManager.AlreadyReply = TodayReply; if (TodayReply >= TweetAccountManager.NoOFReplyPerDay) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Already Replied " + TodayReply + " ]"); return; } } if (chkCheckDatabaseInEvery2Minutes.Checked == true) { while (true) { TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); TwitterDataScrapper.StructTweetIDs item1 = new TwitterDataScrapper.StructTweetIDs(); TweetAccountManager.que_lst_Struct_TweetData.Clear(); Queue<TwitterDataScrapper.StructTweetIDs> tempQueue = new Queue<TwitterDataScrapper.StructTweetIDs>(); TwitterDataScrapper.noOfRecords = 1; AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Searching tweets for " + keyValue.Username + " ]"); TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New_New(txtTweetKeyword.Text.Trim()); int count = TweetAccountContainer.dictionary_TweetAccount.Count(); foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData) { for (int i = 1; i <= count; i++) { TweetAccountManager.que_lst_Struct_TweetData.Enqueue(item); tempQueue.Enqueue(item); } } if (TweetAccountManager.que_lst_Struct_TweetData.Count > 0) { item1 = tempQueue.Dequeue(); } clsDBQueryManager DbQueryManager = new clsDBQueryManager(); DataSet Ds = DbQueryManager.SelectMessageDataForRetweet(keyValue.Username, item1.ID_Tweet, "Reply"); int count_NO_RoWs = Ds.Tables[0].Rows.Count; if (count_NO_RoWs == 0) { tweetAccountManager.Reply(listTweetMessages, replyMinDealy, replyMaxDealy); } AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Search tweets after 3 minutes "); Thread.Sleep(3 * 60 * 1000); } } else { tweetAccountManager.Reply("", replyMinDealy, replyMaxDealy); } tweetAccountManager.Reply("", replyMinDealy, replyMaxDealy); //tweetAccountManager.getmentions(); tweetAccountManager.logEvents.addToLogger -= logEvents_Tweet_addToLogger; tweetAccountManager.tweeter.logEvents.addToLogger -= logEvents_Tweet_addToLogger; } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadPoolMethod_Reply() --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadPoolMethod_Reply() --> " + ex.Message, Globals.Path_TwtErrorLogs); } finally { counter_AccountFollwer--; if (counter_AccountFollwer == 0) { if (btnStartFollowing.InvokeRequired) { btnStartReplying.Invoke(new MethodInvoker(delegate { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]"); AddToLog_Tweet("---------------------------------------------------------------------------------------------------------------------------"); })); } } } }
private void ThreadpoolMethod_Retweet(object parameters) { TweetAccountManager tweetAccountManager = new TweetAccountManager(); try { Array paramsArray = new object[1]; paramsArray = (Array)parameters; KeyValuePair<string, TweetAccountManager> keyValue = (KeyValuePair<string, TweetAccountManager>)paramsArray.GetValue(0); List<TwitterDataScrapper.StructTweetIDs> lst_DivideTweets = new List<TwitterDataScrapper.StructTweetIDs>(); if (TweetAccountManager.IsRetweetDivideRetweet) { lst_DivideTweets = (List<TwitterDataScrapper.StructTweetIDs>)paramsArray.GetValue(1); } tweetAccountManager = keyValue.Value; AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Starting ReTweet For Account : " + keyValue.Key + " ]"); //Add to Threads Dictionary AddThreadToDictionary(strModule(Module.Retweet), tweetAccountManager.Username); try { //Thread.CurrentThread.Name = "ReTweet_" + tweetAccountManager.Username; //Thread.CurrentThread.IsBackground = true; //dictionary_Threads.Add("ReTweet_" + tweetAccountManager.Username, Thread.CurrentThread); AddThreadToDictionary(strModule(Module.Retweet), tweetAccountManager.Username); } catch { } //Create logger Event for lof MSg's . tweetAccountManager.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); //tweetAccountManager.logEvents.addToLogger += logEvents_Tweet_addToLogger; tweetAccountManager.tweeter.logEvents.addToLogger += logEvents_Tweet_addToLogger; if (GlobusRegex.ValidateNumber(txtMinDelay_Tweet.Text)) { retweetMinDealy = Convert.ToInt32(txtMinDelay_Tweet.Text); } if (GlobusRegex.ValidateNumber(txtMaxDelay_Tweet.Text)) { retweetMaxDealy = Convert.ToInt32(txtMaxDelay_Tweet.Text); } if (chkboxRetweetPerDay.Checked) { TweetAccountManager.RetweetPerDay = true; if (!string.IsNullOrEmpty(txtMaximumNoRetweet.Text) && NumberHelper.ValidateNumber(txtMaximumNoRetweet.Text)) { TweetAccountManager.NoOFRetweetPerDay = Convert.ToInt32(txtMaximumNoRetweet.Text); } else { TweetAccountManager.NoOFRetweetPerDay = 10; AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Setting Maximum No Of ReTweets Per Day as 10 ]"); } clsDBQueryManager DbQueryManager = new clsDBQueryManager(); DataSet Ds = DbQueryManager.SelectMessageData(keyValue.Key, "ReTweet"); int TodayReTweet = Ds.Tables["tb_MessageRecord"].Rows.Count; tweetAccountManager.AlreadyRetweeted = TodayReTweet; if (TodayReTweet >= TweetAccountManager.NoOFRetweetPerDay) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Already Retweeted " + tweetAccountManager.AlreadyRetweeted + " ]"); return; } } if (chkCheckDatabaseInEvery2Minutes.Checked == true || chkAutoFavorite.Checked == true) { while (true) { try { string count_tweet = string.Empty; string count_tweet1 = string.Empty; TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); TwitterDataScrapper.StructTweetIDs item1 = new TwitterDataScrapper.StructTweetIDs(); TweetAccountManager.que_lst_Struct_TweetData.Clear(); Queue<TwitterDataScrapper.StructTweetIDs> tempQueue = new Queue<TwitterDataScrapper.StructTweetIDs>(); TwitterDataScrapper.noOfRecords = 1; AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Searching tweets for " + keyValue.Key + " ]"); count_tweet = tweetScrapper.countNoOfTweet(txtTweetKeyword.Text.Trim()); startAgain: TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New_New(txtTweetKeyword.Text.Trim()); int count = TweetAccountContainer.dictionary_TweetAccount.Count(); foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData) { //for (int i = 1; i <= count * TweetAccountManager.static_lst_Struct_TweetData.Count(); i++) { TweetAccountManager.que_lst_Struct_TweetData.Enqueue(item); tempQueue.Enqueue(item); } } try { if (TweetAccountManager.que_lst_Struct_TweetData.Count > 0) { item1 = tempQueue.Dequeue(); } } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs); } try { clsDBQueryManager DbQueryManager = new clsDBQueryManager(); DataSet Ds = DbQueryManager.SelectMessageDataForRetweet(keyValue.Key, item1.ID_Tweet, "ReTweet"); int count_NO_RoWs = Ds.Tables[0].Rows.Count; if (count_NO_RoWs == 0) { if (chkCheckDatabaseInEvery2Minutes.Checked) { tweetAccountManager.ReTweet("", retweetMinDealy, retweetMaxDealy); } if (chkAutoFavorite.Checked && tweetAccountManager.IsNotSuspended && tweetAccountManager.IsLoggedIn) { string TUri = item1.ID_Tweet.ToString(); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Added To Favorite : " + TUri + " from " + tweetAccountManager.Username + " ]"); FavoriteOfUrl(new object[] { TUri, keyValue, tweetAccountManager }); } } AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Searching new tweets will start after 3 minutes from " + tweetAccountManager.Username + " ]"); Thread.Sleep(3 * 60 * 1000); count_tweet1 = tweetScrapper.countNoOfTweet(txtTweetKeyword.Text.Trim()); if (Convert.ToInt32(count_tweet) == Convert.ToInt32(count_tweet1)) { TwitterDataScrapper.noOfRecords = 1; } else if (Convert.ToInt32(count_tweet1) > Convert.ToInt32(count_tweet)) { TwitterDataScrapper.noOfRecords = Convert.ToInt32(count_tweet1) - Convert.ToInt32(count_tweet); } else { TwitterDataScrapper.noOfRecords = 1; } TweetAccountManager.static_lst_Struct_TweetData.Clear(); TweetAccountManager.que_lst_Struct_TweetData.Clear(); tempQueue.Clear(); count_tweet = count_tweet1; } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs); } goto startAgain; } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs); } } } else { if (TweetAccountManager.IsRetweetDivideRetweet) { tweetAccountManager.ReTweetDivideRetweet(lst_DivideTweets, retweetMinDealy, retweetMaxDealy); } else { tweetAccountManager.ReTweet("", retweetMinDealy, retweetMaxDealy); } } tweetAccountManager.logEvents.addToLogger -= logEvents_Tweet_addToLogger; tweetAccountManager.tweeter.logEvents.addToLogger -= logEvents_Tweet_addToLogger; } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs); } finally { tweetAccountManager.logEvents.addToLogger -= logEvents_Tweet_addToLogger; tweetAccountManager.tweeter.logEvents.addToLogger -= logEvents_Tweet_addToLogger; } }
private void StartUnFollowingMultithreaded(object parameters) { try { Array paramsArray = new object[2]; paramsArray = (Array)parameters; int NoOfFollwos = 0; KeyValuePair<string, TweetAccountManager> keyValue = (KeyValuePair<string, TweetAccountManager>)paramsArray.GetValue(0); string NofUnfollows = (string)paramsArray.GetValue(1); if (!string.IsNullOrEmpty(NofUnfollows) && NumberHelper.ValidateNumber(NofUnfollows)) { NoOfFollwos = Int32.Parse(NofUnfollows); } //string userIDToFollow = (string)paramsArray.GetValue(1); List<string> list_userIDsToFollow = new List<string>(); TweetAccountManager tweetAccountManager = keyValue.Value; AddToLog_Unfollow("[ " + DateTime.Now + " ] => [ Unfollowing Process Started For Account : " + keyValue.Key + " ]"); //Add to Threads Dictionary AddThreadToDictionary(strModule(Module.Unfollow), tweetAccountManager.Username); tweetAccountManager.unFollower.logEvents.addToLogger += new EventHandler(logEvents_UnFollower_addToLogger); tweetAccountManager.logEvents.addToLogger += logEvents_UnFollower_addToLogger; if (!tweetAccountManager.IsLoggedIn) { tweetAccountManager.Login(); } if (!tweetAccountManager.IsLoggedIn) { AddToLog_Unfollow("[ " + DateTime.Now + " ] => [ Not Logged In With Account : " + keyValue.Key + " ]"); return; } //AddToLog_Unfollow("Checking for Persons Not Followed Back"); //Check Test box and anf useing feature box is checked if (!string.IsNullOrWhiteSpace(txt_FilePathunfollowUserslist.Text)) { AddToLog_Unfollow("[ " + DateTime.Now + " ] => [ Wait process is running. ]"); //get user deatils from list clsDBQueryManager queryManager = new clsDBQueryManager(); DataTable dt_AlreadyFollowed = queryManager.SelectFollowData(tweetAccountManager.Username); foreach (string item in frmMain_NewUI.lst_unfolloweruserlist) { try { if (chk_dontCheckDbForUnfollow.Checked == false) { try { if (GlobusRegex.ValidateNumber(item)) { continue; } string Status = string.Empty; String UserTimelinePageSource = tweetAccountManager.globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + item), "", ""); ///Get user ID /// string userID = string.Empty; //try //{ // int startIndx = UserTimelinePageSource.IndexOf("data-user-id=\"") + "data-user-id=\"".Length; // int endIndx = UserTimelinePageSource.IndexOf("\"", startIndx); // userID = UserTimelinePageSource.Substring(startIndx, endIndx - startIndx); //} //catch { } try { userID = string.Empty; #region commentedRegionForUserId //string[] useridarr = System.Text.RegularExpressions.Regex.Split(UserTimelinePageSource, "data-user-id="); //foreach (string useridarr_item in useridarr) //{ // if (useridarr_item.Contains("profile-field")) // { // userID = useridarr_item.Substring(0 + 1, useridarr_item.IndexOf("<h1") - 3).Replace("\">\n", string.Empty).Trim(); // list_userIDsToFollow.Add(userID); // break; // } //} #endregion try { int startindex = UserTimelinePageSource.IndexOf("profile_id"); string start = UserTimelinePageSource.Substring(startindex).Replace("profile_id", ""); int endindex = start.IndexOf(","); string end = start.Substring(0, endindex).Replace(""", "").Replace("\"", "").Replace(":", "").Trim(); userID = end.Trim(); list_userIDsToFollow.Add(userID); } catch { } } catch { } } catch { }; } else { //Get user data // if uploaded list value is user name //get id from user name if (GlobusRegex.ValidateNumber(item)) { try { DataRow[] filteredRows = dt_AlreadyFollowed.Select(string.Format("{0} LIKE '%{1}%'", "following_id", item)); if (filteredRows.Count() > 0) { list_userIDsToFollow.Add(filteredRows[0].ItemArray[2].ToString()); } else { AddToLog_UnFollower("[ " + DateTime.Now + " ] => [ " + item + " Does not Followed by " + tweetAccountManager.Username + " ]"); } } catch { }; } else { try { string outstr = string.Empty; DataRow[] filteredRows = dt_AlreadyFollowed.Select(string.Format("{0} LIKE '%{1}%'", "following_username", item)); if (filteredRows.Count() > 0) { if (!string.IsNullOrEmpty(filteredRows[0].ItemArray[2].ToString())) { list_userIDsToFollow.Add(filteredRows[0].ItemArray[2].ToString()); } else if (filteredRows.Count() > 1 && !string.IsNullOrEmpty(filteredRows[1].ItemArray[2].ToString())) { list_userIDsToFollow.Add(filteredRows[1].ItemArray[2].ToString()); } else { AddToLog_UnFollower("[ " + DateTime.Now + " ] => [ " + item + " ID unavaliable. ]"); } } else { AddToLog_UnFollower("[ " + DateTime.Now + " ] => [ " + item + " Does not Followed by " + tweetAccountManager.Username + " ]"); //string status = string.Empty; //var abc = TwitterDataScrapper.GetUsernameToUserID_New(item, out status, ref tweetAccountManager.globusHttpHelper); //list_userIDsToFollow.Add(abc.ToString()); } } catch { }; } } } catch (Exception) { } if (list_userIDsToFollow.Count == TweetAccountManager.noOfUnfollows) { break; } } } else if (rdoUnfollowNotFollowing.Checked) { if (chkUnfollowDateFilter.Checked) { if (!string.IsNullOrEmpty(txtUnfollowFilterDays.Text) && GlobusRegex.ValidateNumber(txtUnfollowFilterDays.Text)) { int days = int.Parse(txtUnfollowFilterDays.Text); list_userIDsToFollow = tweetAccountManager.GetNonFollowingsBeforeSpecifiedDate(days, ref tweetAccountManager); } } else { list_userIDsToFollow = tweetAccountManager.GetNonFollowings(); } } else { TwitterDataScrapper DataScraper = new TwitterDataScrapper(); string Returnstatus = string.Empty; TwitterDataScrapper.NoOfFollowingsToBeunfollowed = NoOfFollwos; DataScraper.CounterDataNo = NoOfFollwos; AddToLog_Unfollow("[ " + DateTime.Now + " ] => [ Scraping Following For : " + tweetAccountManager.Username + " ]"); //DataScraper.logEvents.addToLogger += new EventHandler(); DataScraper.logEvents.addToLogger += new EventHandler(logEvents_UnFollower_addToLogger); list_userIDsToFollow = DataScraper.GetFollowings_New(tweetAccountManager.Screen_name, out Returnstatus, ref tweetAccountManager.globusHttpHelper); if (list_userIDsToFollow.Count != 0) { List<string> temp_userIDsToFollow = new List<string>(); list_userIDsToFollow.ForEach(s => { if (s.Contains(':')) { temp_userIDsToFollow.Add(s.Split(':')[0]); } else { temp_userIDsToFollow.Add(s.ToString()); } }); if (temp_userIDsToFollow.Count != 0) { list_userIDsToFollow.Clear(); list_userIDsToFollow.AddRange(temp_userIDsToFollow); } } AddToLog_Unfollow("[ " + DateTime.Now + " ] => [ " + list_userIDsToFollow.Count + " Following Scraped For : " + tweetAccountManager.Username + " ]"); TwitterDataScrapper.NoOfFollowingsToBeunfollowed = 0; DataScraper.logEvents.addToLogger -= new EventHandler(logEvents_UnFollower_addToLogger); } if (GlobusRegex.ValidateNumber(txtUnfollowMinDelay.Text)) { unfollowMinDelay = Convert.ToInt32(txtUnfollowMinDelay.Text); } if (GlobusRegex.ValidateNumber(txtUnfollowMaxDelay.Text)) { unfollowMaxDealy = Convert.ToInt32(txtUnfollowMaxDelay.Text); } tweetAccountManager.UnFollowUsingURLs(list_userIDsToFollow, unfollowMinDelay, unfollowMaxDealy); tweetAccountManager.unFollower.logEvents.addToLogger -= logEvents_UnFollower_addToLogger; tweetAccountManager.logEvents.addToLogger -= logEvents_UnFollower_addToLogger; } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> StartUnFollowingMultithreaded() --> " + ex.Message, Globals.Path_UnfollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> StartUnFollowingMultithreaded() --> " + ex.Message, Globals.Path_TwtErrorLogs); } finally { counter_Account--; if (counter_Account == 0) { if (btnStartUnfollowing.InvokeRequired) { btnStartUnfollowing.Invoke(new MethodInvoker(delegate { AddToLog_Unfollow("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]"); AddToLog_Unfollow("---------------------------------------------------------------------------------------------------------------------------"); btnStartUnfollowing.Cursor = Cursors.Default; })); } } } }
private void ScrapeKeywordSeacrh() { try { TwitterDataScrapper TweetData = new TwitterDataScrapper(); txtRecords.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txtRecords.Text.Trim()) && NumberHelper.ValidateNumber(txtRecords.Text.Trim())) { TwitterDataScrapper.noOfRecords = Convert.ToInt32(txtRecords.Text.Trim()); if (TwitterDataScrapper.noOfRecords == 0) { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Do not put Zero value ]"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Default number of records is 100 ]"); TwitterDataScrapper.noOfRecords = 100; } } else { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ please enter value in number of users ]"); return; } })); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Scrape by Keyword ]"); //List<TwitterDataScrapper.StructTweetIDs> data = TweetData.GetTweetData(txtScrapeKeyword.Text); //TweetData.logEvents.addToLogger += new EventHandler(DataScraperlogger_addToLogger); TweetData.logEvents.addToLogger += new EventHandler(DataScraperlogger_addToLogger); List<TwitterDataScrapper.StructTweetIDs> data = new List<TwitterDataScrapper.StructTweetIDs>(); foreach (string itemKeyword in lstSearchByKeywords) { if (!chkSearchByKeyWordByPeople.Checked) { data = TweetData.NewKeywordStructDataForSearchByKeyword(itemKeyword.Trim()); data = data.Distinct().ToList(); } else { data = TweetData.NewKeywordStructDataSearchByPeople(itemKeyword.Trim()); } } //TweetData.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); TweetData.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); data = DistinctDataList(data); if (!(data.Count() > 0)) { //AddToScrapeLogs("Request Not Completed"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Requesting For 100 User ids ]"); data = TweetData.NewKeywordStructData(txtScrapeKeyword.Text); } // AddToScrapeLogs("[ " + DateTime.Now + " ] => [ " + data.Count + " User ids Scraped ]"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Please Wait Till Data Is Retrieving ]"); #region commentedRegion //if (!chkSearchByKeyWordByPeople.Checked) //{ // if (!File.Exists(Globals.Path_KeywordScrapedListData + "-" + txtScrapeKeyword.Text + ".csv")) // { // GlobusFileHelper.AppendStringToTextfileNewLine("USERID , USERNAME , PROFILE NAME , BIO , LOCATION , WEBSITE , NO OF TWEETS , FOLLOWERS , FOLLOWINGS", Globals.Path_KeywordScrapedListData + "-" + txtScrapeKeyword.Text + ".csv"); // } // foreach (TwitterDataScrapper.StructTweetIDs item in data) // { // string ProfileName = string.Empty; // string Location = string.Empty; // string Bio = string.Empty; // string website = string.Empty; // string NoOfTweets = string.Empty; // string Followers = string.Empty; // string Followings = string.Empty; // ChilkatHttpHelpr objChilkat = new ChilkatHttpHelpr(); // GlobusHttpHelper HttpHelper = new GlobusHttpHelper(); // string ProfilePageSource = HttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + item.username__Tweet_User), "", ""); // string Responce = ProfilePageSource; // #region Convert HTML to XML // string xHtml = objChilkat.ConvertHtmlToXml(Responce); // Chilkat.Xml xml = new Chilkat.Xml(); // xml.LoadXml(xHtml); // Chilkat.Xml xNode = default(Chilkat.Xml); // Chilkat.Xml xBeginSearchAfter = default(Chilkat.Xml); // #endregion // int counterdata = 0; // xBeginSearchAfter = null; // string dataDescription = string.Empty; // //xNode = xml.SearchForAttribute(xBeginSearchAfter, "span", "class", "profile-field"); // xNode = xml.SearchForAttribute(xBeginSearchAfter, "h1", "class", "ProfileHeaderCard-name"); // while ((xNode != null)) // { // xBeginSearchAfter = xNode; // if (counterdata == 0) // { // ProfileName = xNode.AccumulateTagContent("text", "script|style"); // counterdata++; // } // else if (counterdata == 1) // { // website = xNode.AccumulateTagContent("text", "script|style"); // if (website.Contains("Twitter Status")) // { // website = "N/A"; // } // counterdata++; // } // else // { // break; // } // //xNode = xml.SearchForAttribute(xBeginSearchAfter, "span", "class", "profile-field"); // xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "u-textUserColor"); // } // xBeginSearchAfter = null; // dataDescription = string.Empty; // xNode = xml.SearchForAttribute(xBeginSearchAfter, "p", "class", "ProfileHeaderCard-bio u-dir");//bio profile-field"); // while ((xNode != null)) // { // xBeginSearchAfter = xNode; // Bio = xNode.AccumulateTagContent("text", "script|style").Replace("'", "'").Replace(" ", string.Empty).Trim(); // break; // } // xBeginSearchAfter = null; // dataDescription = string.Empty; // //xNode = xml.SearchForAttribute(xBeginSearchAfter, "span", "class", "location profile-field"); // xNode = xml.SearchForAttribute(xBeginSearchAfter, "span", "class", "ProfileHeaderCard-locationText u-dir");//location profile-field"); // while ((xNode != null)) // { // xBeginSearchAfter = xNode; // Location = xNode.AccumulateTagContent("text", "script|style"); // break; // } // int counterData = 0; // xBeginSearchAfter = null; // dataDescription = string.Empty; // //xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "data-element-term", "tweet_stats"); // xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-nav"); // while ((xNode != null)) // { // xBeginSearchAfter = xNode; // if (counterData == 0) // { // NoOfTweets = xNode.AccumulateTagContent("text", "script|style").Replace("Tweets", string.Empty).Replace(",", string.Empty).Replace("Tweet", string.Empty); // counterData++; // } // else if (counterData == 1) // { // Followings = xNode.AccumulateTagContent("text", "script|style").Replace(" Following", string.Empty).Replace(",", string.Empty).Replace("Following", string.Empty); // counterData++; // } // else if (counterData == 2) // { // Followers = xNode.AccumulateTagContent("text", "script|style").Replace("Followers", string.Empty).Replace(",", string.Empty).Replace("Follower", string.Empty); // counterData++; // } // else // { // break; // } // //xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "js-nav"); // xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-openSignupDialog js-nonNavigable u-textUserColor"); // } // if (!string.IsNullOrEmpty(item.username__Tweet_User) && item.ID_Tweet_User != "null") // { // string Id_user = item.ID_Tweet_User.Replace("}]", string.Empty).Trim(); // Globals.lstScrapedUserIDs.Add(Id_user); // GlobusFileHelper.AppendStringToTextfileNewLine(Id_user + "," + item.username__Tweet_User + "," + ProfileName + "," + Bio.Replace(",", "") + "," + Location.Replace(",", "") + "," + website + "," + NoOfTweets.Replace(",", "").Replace("Tweets", "") + "," + Followers.Replace(",", "").Replace("Following", "") + "," + Followings.Replace(",", "").Replace("Followers", "").Replace("Follower", ""), Globals.Path_KeywordScrapedListData + "-" + txtScrapeKeyword.Text + ".csv"); // AddToScrapeLogs("[ " + DateTime.Now + " ] => [ " + Id_user + "," + item.username__Tweet_User + "," + ProfileName + "," + Bio.Replace(",", "") + "," + Location + "," + website + "," + NoOfTweets + "," + Followers + "," + Followings + " ]"); // } // } //} #endregion //AddToScrapeLogs("Retrieving data"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Adding Data To DataBase ]"); Globals.lstScrapedUserIDs = Globals.lstScrapedUserIDs.Distinct().ToList(); thread_AddingKeywordScrape = new Thread(() => { foreach (TwitterDataScrapper.StructTweetIDs item in data) { if (!string.IsNullOrEmpty(item.username__Tweet_User) && item.ID_Tweet_User != "null") { //AddToScrapeLogs(item.ID_Tweet_User); clsDBQueryManager DataBase = new clsDBQueryManager(); DataBase.InsertOrUpdateScrapeSetting(item.ID_Tweet_User, item.username__Tweet_User, item.ID_Tweet); } } AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Exported location :- " + Globals.Path_KeywordScrapedList + " ]"); AddToScrapeLogs("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]"); AddToScrapeLogs("------------------------------------------------------------------------------------------------------------------------------------------"); }); thread_AddingKeywordScrape.Start(); if (Globals.IsDirectedFromFollower) { Thread.Sleep(1000); Globals.IsDirectedFromFollower = false; AddToLog_Follower("[ " + DateTime.Now + " ] => [ " + data.Count + " User ids Scraped and Added To Follow List ]"); Tb_AccountManager.Invoke(new MethodInvoker(delegate { Tb_AccountManager.SelectedIndex = 2; })); //tabMain.SelectedIndex = 2; } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ScrapeKeywordSeacrh() --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ScrapeKeywordSeacrh() --> " + ex.Message, Globals.Path_TwtErrorLogs); } }
public void btn_FollowByKeyWordStart_Click(object sender, EventArgs e) { CheckNetConn = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); if (CheckNetConn) { if (!string.IsNullOrEmpty(txt_FollowBySearchKey.Text)) { objclsSettingDB.InsertOrUpdateSetting("Follower", "FollowBySearchKey", StringEncoderDecoder.Encode(txt_FollowBySearchKey.Text)); } if (IsFollowByKeyWordStart) { IsFollowByKeyWordStart = false; // new Thread(() => // { Dic_Thread.Clear(); Thread.CurrentThread.Name = "Thread_FollowByKeyword"; Dic_Thread.Add(Thread.CurrentThread.Name, Thread.CurrentThread); //TweetAccountManager TweetAccountManager = new TweetAccountManager(); //TwitterDataScrapper TwitterDataScrapper = new TwitterDataScrapper(); //int FollowLimitCounter = 0; //int AccountCounter = 0; FollowtweetKeywordList.ForEach(i => { searchkeywordqueue.Enqueue(i); }); int NoOfThreads = int.Parse(txtNoOfFollowThreads.Text); int DelayStart = 0; int DelayEnd = 0; bool _IsValue = false; _IsValue = int.TryParse((txtFollowMinDelay.Text), out DelayStart); if (!_IsValue) { IsFollowByKeyWordStart = true; return; } _IsValue = false; _IsValue = int.TryParse((txtFollowMaxDelay.Text), out DelayEnd); if (!_IsValue) { IsFollowByKeyWordStart = true; return; } string SeachKey = string.Empty; List<TwitterDataScrapper.StructTweetIDs> KeywordStructData = new List<TwitterDataScrapper.StructTweetIDs>(); TwitterDataScrapper TwitterDataScrapper = new TwitterDataScrapper(); if (FollowtweetKeywordList.Count != 0) { //TwitterDataScrapper.noOfRecords = int.Parse(txt_FollowByPerAccount.Text); txt_FollowByPerAccount.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txt_FollowByPerAccount.Text)) { TwitterDataScrapper.noOfRecords = int.Parse(txt_FollowByPerAccount.Text); } else { TwitterDataScrapper.noOfRecords = 5; } })); if (!chk_followbysinglekeywordperaccount.Checked) { try { if (searchkeywordqueue.Count == 0) { return; } SeachKey = searchkeywordqueue.Dequeue().ToString();//FollowtweetKeywordList[counterThreadsFollowByKeyWord]; AddToLog_Follower("[ " + DateTime.Now + " ] => [ Start Scraping User for keyword= " + SeachKey + " ]"); KeywordStructData = TwitterDataScrapper.GetTweetData_New(SeachKey); if (KeywordStructData.Count == 0) { KeywordStructData = TwitterDataScrapper.NewKeywordStructData(SeachKey); } } catch (Exception) { } } else { //TwitterDataScrapper.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); foreach (string SeachKey_item in FollowtweetKeywordList) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Start Scraping User for keyword= " + SeachKey_item + " . ]"); List<TwitterDataScrapper.StructTweetIDs> KeywordStructData1 = new List<TwitterDataScrapper.StructTweetIDs>(); int datacounter = 0; KeywordStructData1 = TwitterDataScrapper.NewKeywordStructData1(SeachKey_item); if (KeywordStructData1.Count == 0) { KeywordStructData1 = TwitterDataScrapper.KeywordStructData(SeachKey_item); } if (KeywordStructData1.Count == 0) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Key Word is not Exist/suspended. ]"); } foreach (var KeywordStructData1_item in KeywordStructData1) { if (datacounter == TwitterDataScrapper.noOfRecords) { break; } else { KeywordStructData.Add(KeywordStructData1_item); datacounter++; } } } } } else { MessageBox.Show("Please Upload Keywords"); //break; } List<List<TwitterDataScrapper.StructTweetIDs>> list_lstTargetUsers = new List<List<TwitterDataScrapper.StructTweetIDs>>(); int index = 0; if (chkUseDivide.Checked || IsUsingDivideData) { int splitNo = 0; if (rdBtnDivideEqually.Checked) { splitNo = KeywordStructData.Count / TweetAccountContainer.dictionary_TweetAccount.Count; } else if (rdBtnDivideByGivenNo.Checked) { if (!string.IsNullOrEmpty(txtScrapeNoOfUsers.Text) && NumberHelper.ValidateNumber(txtScrapeNoOfUsers.Text)) { int res = Convert.ToInt32(txtScrapeNoOfUsers.Text); splitNo = res;//listUserIDs.Count / res; } } if (splitNo == 0) { splitNo = RandomNumberGenerator.GenerateRandom(0, KeywordStructData.Count - 1); } list_lstTargetUsers = Split(KeywordStructData, splitNo); } if (TweetAccountContainer.dictionary_TweetAccount.Count > 0) { NoOfLoadAccount = TweetAccountContainer.dictionary_TweetAccount.Count; try { double Num; bool isNum = double.TryParse((txt_FollowByPerAccount.Text.Trim()), out Num); if (isNum) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Start process from follow by search keyword. ]"); ThreadPool.SetMaxThreads(NoOfThreads, 5); foreach (KeyValuePair<string, TweetAccountManager> item in TweetAccountContainer.dictionary_TweetAccount) { #region << Old Code >> //string profileUsername = string.Empty; //string profileUserpass = string.Empty; //profileUsername = item.Key; //profileUserpass = item.Value.Password; ////******search profile By keyWords //string SeachKey = string.Empty; //List<TwitterDataScrapper.StructTweetIDs> KeywordStructData = new List<TwitterDataScrapper.StructTweetIDs>(); //if (FollowtweetKeywordList.Count != 0) //{ // if (!chk_followbysinglekeywordperaccount.Checked) // { // try // { // SeachKey = FollowtweetKeywordList[AccountCounter]; // KeywordStructData = TwitterDataScrapper.GetTweetData_New(SeachKey); // if (KeywordStructData.Count == 0) // { // KeywordStructData = TwitterDataScrapper.NewKeywordStructData(SeachKey); // } // } // catch (Exception) // { // } // } // else // { // foreach (string SeachKey_item in FollowtweetKeywordList) // { // List<TwitterDataScrapper.StructTweetIDs> KeywordStructData1 = new List<TwitterDataScrapper.StructTweetIDs>(); // int datacounter = 0; // KeywordStructData1 = TwitterDataScrapper.NewKeywordStructData(SeachKey_item); // if (KeywordStructData1.Count == 0) // { // KeywordStructData1 = TwitterDataScrapper.KeywordStructData(SeachKey_item); // } // if (KeywordStructData1.Count == 0) // { // AddToLog_Follower("Key Word is not Exist/suspended."); // } // foreach (var KeywordStructData1_item in KeywordStructData1) // { // if (datacounter == int.Parse(txt_FollowByPerAccount.Text)) // { // break; // } // else // { // KeywordStructData.Add(KeywordStructData1_item); // datacounter++; // } // } // } // } //} //else //{ // MessageBox.Show("Please Upload Keywords"); // break; //} ////************* //try //{ // if (KeywordStructData.Count > 0) // { // TweetAccountManager AccountManager = (TweetAccountManager)item.Value; // AccountManager.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); // int DelayStart = 0; // int DelayEnd = 0; // bool _IsValue = false; // _IsValue = int.TryParse((txtFollowMinDelay.Text), out DelayStart); // if (!_IsValue) // { // return; // } // _IsValue = false; // _IsValue = int.TryParse((txtFollowMaxDelay.Text), out DelayEnd); // if (!_IsValue) // { // return; // } // if (!AccountManager.IsLoggedIn) // { // AccountManager.Login(); // } // foreach (var item1 in KeywordStructData) // { // if (!chk_followbysinglekeywordperaccount.Checked) // { // //accordint to get Follow users limits // if (FollowLimitCounter >= (int.Parse(txt_FollowByPerAccount.Text))) // { // FollowLimitCounter = 0; // break; // } // else // { // FollowLimitCounter++; // } // } // //Get follow from user // string AccountId = item1.ID_Tweet_User; // ///Return if Suspended // if (AccountManager.AccountStatus == "Account Suspended") // { // AddToLog_Follower(profileUsername + " : Suspended"); // break; // } // else if ((AccountManager.globusHttpHelper.gResponse.ResponseUri.ToString().ToLower()).Contains("captcha")) // { // AddToLog_Follower(profileUsername + " : Asking for captcha."); // break; // } // getFollowUserBySearch(new object[] { AccountManager, AccountId }); // int Delay = RandomNumberGenerator.GenerateRandom(DelayStart, DelayEnd); // AddToLog_Follower("Delay :- " + Delay + " Seconds."); // Thread.Sleep(Delay); // } // } // else // { // //Message List is Empty // AddToLog_Follower("Key Word File is Empty or Wrong Formate"); // break; // } //} //catch (Exception) //{ //} //if (AccountCounter > TweetAccountContainer.dictionary_TweetAccount.Count) //{ // AccountCounter = 0; //} //else //{ // AccountCounter++; //} #endregion if (counterThreadsFollowByKeyWord >= NoOfThreads) { lock (lockerThreadsFollowByKeyWord) { Monitor.Wait(lockerThreadsFollowByKeyWord); } } if (chkUseDivide.Checked || IsUsingDivideData) { KeywordStructData = list_lstTargetUsers[index]; } //ThreadPool.QueueUserWorkItem(new WaitCallback(StartFollowByKeyWord), new object[] { item, DelayStart, DelayEnd }); Thread threadGetStartProcessForfollow = new Thread(StartFollowByKeyWord); threadGetStartProcessForfollow.Name = "Thread_FollowByKeyword" + "_" + item.Key; threadGetStartProcessForfollow.IsBackground = true; threadGetStartProcessForfollow.Start(new object[] { item, DelayStart, DelayEnd, KeywordStructData }); index++; Thread.Sleep(1000); } }//isNum If End else { MessageBox.Show("Please enter No of follow By per account"); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Please enter No of follow By per account ]"); } } catch (Exception) { } finally { //if (FollowtweetKeywordList.Count == 0) //{ // AddToLog_Follower("Please Upload Keywords"); //} //else //{ // AddToLog_Follower("Follow By key Word Process is Finished."); //} } } else { MessageBox.Show("Please Upload Twitter Account"); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Please Upload Twitter Account ]"); } IsFollowByKeyWordStart = true; // }).Start(); } } else { MessageBox.Show("Your Internet Connection is disabled ! or not working, Please Check Your Internet Connection..."); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Your Internet Connection is disabled ! or not working, Please Check Your Internet Connection... ]"); } }
public void TweetDataExtract() { try { if (!string.IsNullOrEmpty(txtTweetExtractCount.Text) && NumberHelper.ValidateNumber(txtTweetExtractCount.Text)) { TweetExtractCount = Convert.ToInt32(txtTweetExtractCount.Text); if (TweetExtractCount > 2500) { TwitterDataScrapper.TweetExtractCount = 2100; AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Extracting Default No Of Tweet : 2100 ]"); } else { TwitterDataScrapper.TweetExtractCount = TweetExtractCount; } } else { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Entered Count incorrect.Setting Default Count 10 ]"); } //Remove Options of RT or @ mentions MSG's if (chk_RTMSG.Checked) { TwitterDataScrapper.RemoveRTMSg = true; } if (chk_RemoveAtMsg.Checked) { TwitterDataScrapper.removeAtMentions = true; } int counter = 0; TwitterDataScrapper DataScraper = new TwitterDataScrapper(); foreach (string item in lstUserId_Tweet) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Extracting Tweets For " + item + " ]"); string ReturnStatus = string.Empty; List<string> TweetData = new List<string>(); //if (TwitterDataScrapper.RemoveRTMSg == true) //{ // TweetData = DataScraper.GetOnlyTweetData_Scrape(item, TweetExtractCount, out ReturnStatus); //} //else //{ TweetData = DataScraper.GetTweetData_Scrape(item, TweetExtractCount, out ReturnStatus); //} //List<TwitterDataScrapper.StructTweetIDs> tweetData = DataScraper.TweetExtractor_ByUserName_New(item); if (ReturnStatus.Contains("No Error")) { if (TweetData.Count > 0) { foreach (string newItem in TweetData) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + newItem + " ]"); } } else { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Sorry No Tweets For " + item + " ]"); } } else if (ReturnStatus.Contains("Rate limit exceeded")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Rate limit exceeded ]"); break; } else if (ReturnStatus.Contains("Sorry, that page does not exist")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + item + " >>> Sorry, that page does not exist ]"); } else if (ReturnStatus.Contains("Empty")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + item + " >>>> Return Empty ]"); } else { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + item + " >>> Error in Request ]"); } } AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Finished Extracting Tweets ]"); AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Tweets Stored In -" + Globals.Path_TweetExtractor + " ]"); AddToTweetCreatorLogs("-----------------------------------------------------------------------------------------------------------------------"); //if (txtTweetName.InvokeRequired) //{ // txtTweetName.Invoke(new MethodInvoker(delegate // { // txtTweetName.Text = ""; // })); //} if (txtExtractorFile.InvokeRequired) { txtExtractorFile.Invoke(new MethodInvoker(delegate { txtExtractorFile.Text = ""; })); } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetDataExtract() --> " + ex.Message, Globals.Path_TweetCreatorErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> TweetDataExtract() --> " + ex.Message, Globals.Path_TwtErrorLogs); } }
/// <summary> /// Get Followers ID from page source /// when APi is not working ... /// </summary> /// <param name="userID"></param> /// <param name="Ghelper"></param> /// <returns></returns> public List<string> GetFollowersUsingUserID1(string userID, GlobusHttpHelper Ghelper) { List<string> list_Followers = new List<string>(); TwitterDataScrapper followerScrapper = new TwitterDataScrapper(); string returnstatus = string.Empty; list_Followers = followerScrapper.GetFollowers_New(userID, out returnstatus, ref Ghelper); //list_Followers = followerScrapper.GetFollowers1(userID, out returnstatus, Ghelper); //AddToLog_Follower(returnstatus);GetFollowers_New return list_Followers; }
private void btnStartReplying_Click(object sender, EventArgs e) { CheckNetConn = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); try { TweetAccountManager.static_lst_Struct_TweetData.Clear(); } catch { } List<TwitterDataScrapper.StructTweetIDs> static_lst_Struct_TweetDataTemp = new List<TwitterDataScrapper.StructTweetIDs>(); if (CheckNetConn) { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Starting Replying ]"); if (chkboxRetweetPerDay.Checked) { MessageBox.Show("Please Check Reply Per Day or No Of Reply"); return; } if (chkReplyBySpecificTweet.Checked) { foreach (TwitterDataScrapper.StructTweetIDs item in lst_structTweetIDs) { TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Enqueue(item); } if (TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Count > 0 && listTweetMessages.Count >= 1) { StartReplying(); } else { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Please Upload Tweet file or reply message file. ]"); return; } } else { if (listTweetMessages.Count >= 1 && !string.IsNullOrEmpty(txtTweetKeyword.Text.Trim())) //if (!string.IsNullOrEmpty(txtTweetKeyword.Text)) { string tweetKeyword = txtTweetKeyword.Text; if (!chk_retweetbyUser.Checked) { new Thread(() => { try { AddThreadToDictionary(strModule(Module.Reply), "GettingRetweetsByKeyword"); } catch { }; TweetAccountManager.ReplyKeyword = txtTweetKeyword.Text; TweetAccountManager.static_lst_Struct_TweetData = new List<TwitterDataScrapper.StructTweetIDs>(); TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); //tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); // TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.GetTweetData_New(txtTweetKeyword.Text); if (File.Exists(txtTweetKeyword.Text.Trim())) { foreach (string _ReplyKeywordTemp in lstKeywordRetweetUpload) { static_lst_Struct_TweetDataTemp = tweetScrapper.NewKeywordStructData1(_ReplyKeywordTemp); TweetAccountManager.static_lst_Struct_TweetData.AddRange(static_lst_Struct_TweetDataTemp); } } else { TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.NewKeywordStructData1(tweetKeyword); } //TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.NewKeywordStructData1(tweetKeyword); tweetScrapper.logEvents.addToLogger -= new EventHandler(logEvents_Tweet_addToLogger); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + TweetAccountManager.static_lst_Struct_TweetData.Count + " Tweets found ]"); //AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + TweetAccountManager.static_lst_Struct_TweetData.Count + " Tweets From Keyword : " + txtTweetKeyword.Text + " ]"); foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData) { TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Enqueue(item); } if (TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Count > 0) { StartReplying(); } else { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Data is not available from searching Keyword :- " + txtTweetKeyword.Text + " ]"); } }).Start(); } else { new Thread(() => { try { AddThreadToDictionary(strModule(Module.Reply), "GettingRetweetsByUsername"); } catch { }; TweetAccountManager.ReplyKeyword = txtTweetKeyword.Text; TweetAccountManager.static_lst_Struct_TweetData = new List<TwitterDataScrapper.StructTweetIDs>(); TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); //tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); tweetScrapper.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger); // TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.GetTweetData_New(txtTweetKeyword.Text); if (File.Exists(txtTweetKeyword.Text.Trim())) { static_lst_Struct_TweetDataTemp = new List<TwitterDataScrapper.StructTweetIDs>(); foreach (string _ReplyKeywordTemp in lstKeywordRetweetUpload) { static_lst_Struct_TweetDataTemp = tweetScrapper.TweetExtractor_ByUserName_New_New(_ReplyKeywordTemp); TweetAccountManager.static_lst_Struct_TweetData.AddRange(static_lst_Struct_TweetDataTemp); } } else { static_lst_Struct_TweetDataTemp = tweetScrapper.TweetExtractor_ByUserName_New_New(tweetKeyword); } TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New_New(tweetKeyword); tweetScrapper.logEvents.addToLogger -= new EventHandler(logEvents_Tweet_addToLogger); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + TweetAccountManager.static_lst_Struct_TweetData.Count + " Tweets found ]"); foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData) { TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Enqueue(item); } if (TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Count > 0) { StartReplying(); } else { AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Data is not available from searching Keyword :- " + txtTweetKeyword.Text + " ]"); } }).Start(); } } else { MessageBox.Show("Please upload Tweet Messages File & put a Tweet Search Keyword"); } } } }
public List<string> GetFollowingsUsingUserID(string userID) { List<string> list_Followings = new List<string>(); TwitterDataScrapper followingScrapper = new TwitterDataScrapper(); string returnstatus = string.Empty; list_Followings = followingScrapper.GetFollowings(userID, out returnstatus); //AddToLog_Follower(returnstatus); return list_Followings; }
private void StartUnFollowingMultithreaded(object parameters) { try { if (IsStopFollowYourFollowers) { return; } // if (!IsStopFollowYourFollowers) { lstIsStopFollowYourFollowers.Add(Thread.CurrentThread); lstIsStopFollowYourFollowers.Distinct(); Thread.CurrentThread.IsBackground = true; } Array paramsArray = new object[2]; paramsArray = (Array)parameters; int NoOfFollwos = 0; KeyValuePair<string, TweetAccountManager> keyValue = (KeyValuePair<string, TweetAccountManager>)paramsArray.GetValue(0); string NofUnfollows = (string)paramsArray.GetValue(1); if (!string.IsNullOrEmpty(NofUnfollows) && NumberHelper.ValidateNumber(NofUnfollows)) { NoOfFollwos = Int32.Parse(NofUnfollows); } bool OtherUser = false; frmMain_NewUI.IsFollowerScreenName = true; List<string> list_userIDsToFollow = new List<string>(); TweetAccountManager tweetAccountManager = keyValue.Value; AddToLog_follow("[ " + DateTime.Now + " ] => [following Process Started For Account : " + keyValue.Key + " ]"); //Add to Threads Dictionary //AddThreadToDictionary(strModule(Module.Follow), tweetAccountManager.Username); tweetAccountManager.unFollower.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); tweetAccountManager.logEvents.addToLogger += logEvents_Follower_addToLogger; if (!tweetAccountManager.IsLoggedIn) { tweetAccountManager.Login(); } if (!tweetAccountManager.IsLoggedIn) { AddToLog_follow("[ " + DateTime.Now + " ] => [ Not Logged In With Account : " + keyValue.Key + " ]"); return; } //////////////temp mehtod { } //AddToLog_Unfollow("Checking for Persons Not Followed Back"); Thread thread_UnFollowing = null; //Check Test box and anf useing feature box is checked TwitterDataScrapper objTwitterDataScrapper = new TwitterDataScrapper(); //if (rdoFollowYourFollowers.Checked) //thread_UnFollowing = new Thread(() => //{ // list_userIDsToFollow = tweetAccountManager.GetFollowYourFollowersList(); //}); list_userIDsToFollow = tweetAccountManager.GetFollowYourFollowersList(); if (GlobusRegex.ValidateNumber(txtfollowMinDelay.Text)) { followMinDelay = Convert.ToInt32(txtfollowMinDelay.Text); } if (GlobusRegex.ValidateNumber(txtfollowMaxDelay.Text)) { followMaxDelay = Convert.ToInt32(txtfollowMaxDelay.Text); } if (list_userIDsToFollow.Count > 0) { tweetAccountManager.FollowUsingURLs(list_userIDsToFollow, followMinDelay, followMaxDelay, OtherUser); } else { AddToLog_follow("[ " + DateTime.Now + " ] => [ No user id is available for Account : " + keyValue.Key + " ]"); } tweetAccountManager.unFollower.logEvents.addToLogger -= logEvents_Follower_addToLogger; tweetAccountManager.logEvents.addToLogger -= logEvents_Follower_addToLogger; } catch (Exception ex) { ErrorLogger.AddToErrorLogText(ex.Message); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> StartUnFollowingMultithreaded() --> " + ex.Message, Globals.Path_UnfollowerErroLog); GlobusFileHelper.AppendStringToTextfileNewLine("Error --> StartUnFollowingMultithreaded() --> " + ex.Message, Globals.Path_TwtErrorLogs); } finally { counter_Account--; if (counter_Account == 0) { if (btnStartFollow.InvokeRequired) { btnStartFollow.Invoke(new MethodInvoker(delegate { AddToLog_follow("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]"); AddToLog_follow("---------------------------------------------------------------------------------------------------------------------------"); btnStartFollow.Cursor = Cursors.Default; })); } } } }
public void getHashTags() { TwitterDataScrapper dataScrape = new TwitterDataScrapper(); try { try { lstThreadGetHashTags.Add(Thread.CurrentThread); Thread.CurrentThread.IsBackground = true; lstThreadGetHashTags = lstThreadGetHashTags.Distinct().ToList(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } Globals.HashTags.Clear(); string returnStatus = string.Empty; //dataScrape.logEvents.addToLogger += new EventHandler(DataScraperlogger_addToLogger); dataScrape.logEvents.addToLogger += new EventHandler(DataScraperlogger_addToLogger); Globals.HashTags = dataScrape.GetHashTags_New(out returnStatus); dataScrape.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); //dataScrape.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); try { if (Globals.HashTags.Count > 0) { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ " + Globals.HashTags.Count + " Trending Hash Tags ]"); AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + Globals.HashTags.Count + " Hash Tags In List ]"); foreach (string data in Globals.HashTags) { GlobusFileHelper.AppendStringToTextfileNewLine(data, Globals.Path_HashtagsStore); } AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Hash tag Finished ]"); AddToScrapeLogs("-----------------------------------------------------------------------------------------------------------------------"); if (chkbosUseHashTags.Checked) { btnGetHashTags.Invoke(new MethodInvoker(delegate { Tb_AccountManager.SelectedIndex = 1; })); } } else { AddToScrapeLogs("[ " + DateTime.Now + " ] => [ Rate Limit Exceeded.Please Try After Some Time ]"); } } catch { } } catch { } finally { dataScrape.logEvents.addToLogger -= new EventHandler(DataScraperlogger_addToLogger); } }
public List<string> GetFollowerYourFollowers(ref GlobusHttpHelper Httphelper) { TwitterDataScrapper followerScrapper = new TwitterDataScrapper(); string returnStatus = string.Empty; list_Followers = followerScrapper.GetFollowYourFollowers(userID, Screen_name, out returnStatus, Httphelper); return list_Followers; }
public void RetweetDataExtractor() { try { if (!string.IsNullOrEmpty(txtRetweetCount.Text) && NumberHelper.ValidateNumber(txtRetweetCount.Text)) { RetweetExtractCount = Convert.ToInt32(txtRetweetCount.Text); TwitterDataScrapper.RetweetExtractcount = RetweetExtractCount; } else { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Entered Count incorrect.Setting Default Count 10 ]"); } TwitterDataScrapper DataScraper = new TwitterDataScrapper(); foreach (string item in lstUserId_Retweet) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Extracting ReTweets For " + item + " ]"); string ReturnStatus = string.Empty; List<string> TweetData = DataScraper.GetRetweetData_Scrape(item, out ReturnStatus); if (ReturnStatus.Contains("No Error")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + TweetData.Count + " Retweet From User : "******" ]"); if (TweetData.Count > 0) { //new Thread(() => //{ foreach (string newItem in TweetData) { string[] arry = Regex.Split(newItem, ":"); if (arry.Length == 3) { //AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + arry[0] + " : " + arry[1] + " ]"); //AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + arry[2] + " ]"); clsDBQueryManager DataBase = new clsDBQueryManager(); DataBase.InsertDataRetweet(arry[0], arry[1], arry[2]); } AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + newItem + " ]"); } //}).Start(); } else { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Sorry No ReTweets For " + item + " ]"); } } else if (ReturnStatus.Contains("Rate limit exceeded")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Rate limit exceeded ]"); break; } else if (ReturnStatus.Contains("Sorry, that page does not exist")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + item + " >>> Sorry, that page does not exist ]"); } else if (ReturnStatus.Contains("Empty")) { AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + item + " >>>> Return Empty ]"); } else { //AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ " + item + " >>> Errror in Request ]"); AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ No item Found From User " + item + " ]"); } } AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ ReTweets Stored In -" + Globals.Path_RETweetExtractor + " ]"); AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Finished Extracting ReTweets ]"); AddToTweetCreatorLogs("-----------------------------------------------------------------------------------------------------------------------"); if (txtRetweetFile.InvokeRequired) { txtRetweetFile.Invoke(new MethodInvoker(delegate { txtRetweetFile.Text = ""; })); } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> RetweetDataExtractor() --> " + ex.Message, Globals.Path_TweetCreatorErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> RetweetDataExtractor() --> " + ex.Message, Globals.Path_TwtErrorLogs); } }
public List<string> GetNonFollowingsBeforeSpecifiedDate(int noOfDays, ref TweetAccountManager AcManger) { TwitterDataScrapper followingScrapper = new TwitterDataScrapper(); string status = string.Empty; followingScrapper.CounterDataNo = noOfUnfollows; List<string> followers = followingScrapper.GetFollowers_New(AcManger.Screen_name, out status, ref AcManger.globusHttpHelper); List<string> followings = followingScrapper.GetFollowings_New(AcManger.Screen_name, out status, ref AcManger.globusHttpHelper); List<string> nonFollowings = followings.Except(followers).ToList(); List<string> requiredNonFollowingList = new List<string>(); ///Get list of Already Followings clsDBQueryManager queryManager = new clsDBQueryManager(); DataTable dt_AlreadyFollowed = queryManager.SelectFollowData(Username); foreach (DataRow item in dt_AlreadyFollowed.Rows) { string user_AlreadyFollowed = item["following_id"].ToString(); if (nonFollowings.Exists(s => ((s.Split(':')[0]) == user_AlreadyFollowed))) { DateTime dt_Now = DateTime.Today; string DateFollowed = item["DateFollowed"].ToString(); DateTime dt_DateFollowed1 = Convert.ToDateTime(DateFollowed); //DateTime dt_DateFollowed = DateTime.Parse(String.Format("{0:d/M/yyyy HH:mm:ss}", dt_DateFollowed1)); DateTime dt_DateFollowed = dt_DateFollowed1; TimeSpan dt_Difference = dt_Now.Subtract(dt_DateFollowed); double dt_Difference1 = dt_Difference.Days; if (dt_Difference.Days >= noOfDays) { requiredNonFollowingList.Add(user_AlreadyFollowed); } } } return requiredNonFollowingList; }
public void StartCampaign() { try { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Starting Campaign ]"); string KeywordList = string.Empty; string UsernameList = string.Empty; if (Globals.Array[3] == "Username") { Globals.Campaign_Name = Globals.Array[0]; Globals.IsCampaign = true; AddToLog_Follower("[ " + DateTime.Now + " ] => [ Getting Followers & Following ]"); UsernameList = Globals.Array[1]; ReloadAccountsFromDataBase(); Globussoft.GlobusHttpHelper globusHttpHelper = new GlobusHttpHelper(); if (File.Exists(UsernameList)) { List<string> LstUsernameCampiagn = GlobusFileHelper.ReadLargeFile(UsernameList); listUserIDs = new List<string>(); List<string> ListUsername = new List<string>(); foreach (KeyValuePair<string, TweetAccountManager> item in TweetAccountContainer.dictionary_TweetAccount) { if (counter > TweetAccountContainer.dictionary_TweetAccount.Count) { counter = 0; } TweetAccountManager TweetLogin = new TweetAccountManager(); TweetLogin.Username = item.Key; TweetLogin.Password = item.Value.Password; TweetLogin.proxyAddress = item.Value.proxyAddress; TweetLogin.proxyPort = item.Value.proxyPort; TweetLogin.proxyUsername = item.Value.proxyUsername; TweetLogin.proxyPassword = item.Value.proxyPassword; TweetLogin.Login(); if (!TweetLogin.IsNotSuspended) { continue; } globusHttpHelper = TweetLogin.globusHttpHelper; counter++; break; } foreach (string keyword in LstUsernameCampiagn) { TwitterDataScrapper dataScrapeer = new TwitterDataScrapper(); try { string FollowerStatus = string.Empty; string FollowingStatus = string.Empty; AddToLog_Follower("[ " + DateTime.Now + " ] => [ Scraping Followers For : " + keyword + " ]"); dataScrapeer.CounterDataNo = 2000; dataScrapeer.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); List<string> followerList = dataScrapeer.GetFollowers_New(keyword, out FollowerStatus, ref globusHttpHelper); if (followerList.Count != 0) { try { List<string> Temp_followers = new List<string>(); followerList.ForEach(s => { if (s.Contains(":")) { Temp_followers.Add(s.Split(':')[0]); } else { Temp_followers.Add(s.ToString()); } }); if (Temp_followers.Count != 0) { followerList.Clear(); followerList.AddRange(Temp_followers); } } catch { }; } followerList.ForEach(s => s.Split(':')); dataScrapeer.logEvents.addToLogger -= new EventHandler(logEvents_Follower_addToLogger); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Follower For " + keyword + " >> " + followerList.Count + " ]"); if (FollowerStatus == "No Error") { foreach (string lst in followerList) { listUserIDs.Add(lst); } } Thread.Sleep(5000); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Scraping Followings For : " + keyword + " ]"); dataScrapeer.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); List<string> followingList = dataScrapeer.GetFollowings_New(keyword, out FollowingStatus, ref globusHttpHelper); dataScrapeer.logEvents.addToLogger -= new EventHandler(logEvents_Follower_addToLogger); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Following For " + keyword + " >> " + followingList.Count + " ]"); if (FollowingStatus == "No Error") { foreach (string lst in followerList) { listUserIDs.Add(lst); } } Thread.Sleep(5000); } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> StartingCampaign() -- chkboxScrapeFollowers.Checked --> " + ex.Message, Globals.Path_ScrapeUsersErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> StartingCampaign() -- chkboxScrapeFollowers.Checked --> " + ex.Message, Globals.Path_TwtErrorLogs); } } StartFollowing(); } else { AddToLog_Follower("[ " + DateTime.Now + " ] => [ File : " + UsernameList + ". Does Not Exsist ]"); } } else if (Globals.Array[3] == "Keyword") { KeywordList = Globals.Array[2]; ReloadAccountsFromDataBase(); if (File.Exists(KeywordList)) { List<string> KeywordListdata = GlobusFileHelper.ReadLargeFile(KeywordList); List<TwitterDataScrapper.StructTweetIDs> ids = new List<TwitterDataScrapper.StructTweetIDs>(); foreach (string id in KeywordListdata) { TwitterDataScrapper dataScrpeer = new TwitterDataScrapper(); TwitterDataScrapper.noOfRecords = 2000; AddToLog_Follower("[ " + DateTime.Now + " ] => [ Scraping Users From Keyword : " + id + " ]"); dataScrpeer.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); ids = dataScrpeer.NewKeywordStructData(id); dataScrpeer.logEvents.addToLogger -= new EventHandler(logEvents_Follower_addToLogger); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Total Users From Keyword : " + id + " : " + ids.Count + " ]"); foreach (TwitterDataScrapper.StructTweetIDs lst in ids) { listUserIDs.Add(lst.ID_Tweet_User); } } StartFollowing(); } else { AddToLog_Follower("[ " + DateTime.Now + " ] => [ File : " + KeywordList + ".Does Not Exsist ]"); } } } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Campaign --> startFlyCreationEvent_addToLogger() --> " + ex.Message, Globals.Path_CampaignManager); } }
public void StartWaitAndReply(string tweetKeyword) { List<string> lstTweetImages = new List<string>(); try { if (!IsLoggedIn) { Login(); } int counterDataScraped = 0; if (IsLoggedIn) { if (IsNotSuspended) { TwitterDataScrapper tweetScrapper = new TwitterDataScrapper(); lst_Struct_TweetData = tweetScrapper.GetTweetData_WaitReply(tweetKeyword); Log("[ " + DateTime.Now + " ] => [ Extracted " + lst_Struct_TweetData.Count + " Tweet Ids ]"); if (IsTweetWithImage) { if (!Directory.Exists(ImageFolderPath)) { Log("[ " + DateTime.Now + " ] => [ Image Folder Does't Exist. ]"); return; } ///Load Image ... lstTweetImages = GetImagePathFromFolder(ImageFolderPath); if (lstTweetImages.Count != 0) { if (lstTweetImages.Count < listTweetMessages.Count) { int remaining = listTweetMessages.Count - lstTweetImages.Count; for (int i = 0; i < remaining; i++) { string Imagepath = string.Empty; try { Imagepath = lstTweetImages[i]; } catch (Exception ex) { i = 0; Imagepath = lstTweetImages[i]; } lstTweetImages.Add(Imagepath); } } else { ///if images is greater than messages. } } else { Log("[ " + DateTime.Now + " ] => [ Please Folder is Empty. Please add images in :- " + ImageFolderPath + " ]"); return; } ///print number of Images ... Log("[ " + DateTime.Now + " ] => [ " + lstTweetImages.Count() + " Images uploaded. ]"); foreach (string item in lstTweetImages) { que_ImagePath_WaitAndReply.Enqueue(item); } } while (que_TweetMessages_WaitAndReply.Count > 0) { if (que_ReplyMessages_WaitAndReply.Count <= 0) { break; } if (que_TweetMessages_WaitAndReply.Count <= 0) { break; } #region MyRegion ////Tweet ////listTweetMessages = Randomiser.Shuffle(listTweetMessages).ToList(); //foreach (string item in listTweetMessages) //{ // que_TweetMessages.Enqueue(item); //} ////listTweetMessages = Randomiser.Shuffle(listTweetMessages).ToList(); //foreach (string item in listReplyMessages) //{ // que_ReplyMessages.Enqueue(item); //} #endregion int countTweetsSent = 0; int interval = WaitAndReplyInterval; while (countTweetsSent < noOfTweetsPerReply) { //Tweet string tweetStatus; string tweetMessage = ""; string ImagePath=""; #region MyRegion //if (que_TweetMessages.Count == 0) //{ // //listTweetMessages = Randomiser.Shuffle(listTweetMessages).ToList(); // foreach (string item in listTweetMessages) // { // que_TweetMessages.Enqueue(item); // } //} #endregion lock (locker_que_TweetMessages_WaitAndReply) { if (que_TweetMessages_WaitAndReply.Count > 0) { try { tweetMessage = que_TweetMessages_WaitAndReply.Dequeue(); ImagePath = que_ImagePath_WaitAndReply.Dequeue(); } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- locker_que_TweetMessages_WaitAndReply -- --> " + ex.Message, Globals.Path_WaitNreplyErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- StartWaitAndReply() -- locker_que_TweetMessages_WaitAndReply -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } } else { Log("[ " + DateTime.Now + " ] => [All Loaded Tweet Messages Used ]"); break; } } if (IsTweetWithImage) { tweeter.TweetMessageWithImage(ref globusHttpHelper, postAuthenticityToken, tweetMessage, ImagePath, out tweetStatus); if (tweetStatus == "posted") { Log("[ " + DateTime.Now + " ] => [ Tweeted : " + tweetMessage + " with image:"+ImagePath+" by " + Username + " ]"); clsDBQueryManager DataBase = new clsDBQueryManager(); string dbTweetMessage = StringEncoderDecoder.Encode(tweetMessage); DataBase.InsertMessageData(Username, "Tweet", "", dbTweetMessage); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword+":"+tweetMessage, Globals.path_SuccessfullyTweetAccounts); countTweetsSent++; if (!waitAndReplyIsIntervalInsec) { Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); Thread.Sleep(interval); } else { try { interval = RandomNumberGenerator.GenerateRandom(waitAndReplyMinInterval, waitAndReplyMaxInterval); } catch { } Log("[ " + DateTime.Now + " ] => [ Delay For : " + interval + " seconds. ]"); interval = interval * 1000; Thread.Sleep(interval); } } else { Log("[ " + DateTime.Now + " ] => [ Couldn't Post : " + tweetMessage + " with image:"+ImagePath+" by " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword + ":" + tweetMessage, Globals.path_FailedToTweetAccounts); countTweetsSent++; //Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); //Thread.Sleep(interval); if (!waitAndReplyIsIntervalInsec) { Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); Thread.Sleep(interval); } else { try { interval = RandomNumberGenerator.GenerateRandom(waitAndReplyMinInterval, waitAndReplyMaxInterval); } catch { } Log("[ " + DateTime.Now + " ] => [ Delay For : " + interval + " seconds. ]"); interval = interval * 1000; Thread.Sleep(interval); } } } else { tweeter.Tweet(ref globusHttpHelper, postAuthenticityToken, tweetMessage, out tweetStatus); if (tweetStatus == "posted") { Log("[ " + DateTime.Now + " ] => [ Tweeted : " + tweetMessage + " by " + Username + " ]"); clsDBQueryManager DataBase = new clsDBQueryManager(); string dbTweetMessage = StringEncoderDecoder.Encode(tweetMessage); DataBase.InsertMessageData(Username, "Tweet", "", dbTweetMessage); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword + ":" + tweetMessage, Globals.path_SuccessfullyTweetAccounts); countTweetsSent++; //Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); //Thread.Sleep(interval); if (!waitAndReplyIsIntervalInsec) { Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); Thread.Sleep(interval); } else { try { interval = RandomNumberGenerator.GenerateRandom(waitAndReplyMinInterval, waitAndReplyMaxInterval); } catch { } Log("[ " + DateTime.Now + " ] => [ Delay For : " + interval + " seconds. ]"); interval = interval * 1000; Thread.Sleep(interval); } } else { Log("[ " + DateTime.Now + " ] => [ Couldn't Post : " + tweetMessage + " by " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword + ":" + tweetMessage, Globals.path_FailedToTweetAccounts); countTweetsSent++; //Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); //Thread.Sleep(interval); if (!waitAndReplyIsIntervalInsec) { Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); Thread.Sleep(interval); } else { try { interval = RandomNumberGenerator.GenerateRandom(waitAndReplyMinInterval, waitAndReplyMaxInterval); } catch { } Log("[ " + DateTime.Now + " ] => [ Delay For : " + interval + " seconds. ]"); interval = interval * 1000; Thread.Sleep(interval); } } } } //Reply if (lst_Struct_TweetData.Count == 0) { lst_Struct_TweetData = tweetScrapper.GetTweetData_New(tweetKeyword); } if (lst_Struct_TweetData.Count != 0) { int counter_Reply = 1; //foreach (TwitterDataScrapper.StructTweetIDs item in lst_Struct_TweetData) //{ while (countTweetsSent == counter_Reply * noOfTweetsPerReply && que_ReplyMessages_WaitAndReply.Count > 0) { string replyStatus; string replyMessage = ""; #region MyRegion //if (counter_Reply >= 1) //{ // break; //} //if (que_ReplyMessages.Count == 0) //{ // //listReplyMessages = Randomiser.Shuffle(listReplyMessages).ToList(); // foreach (string ReplyMessage in listReplyMessages) // { // que_ReplyMessages.Enqueue(ReplyMessage); // } //} #endregion lock (locker_que_ReplyMessage_WaitAndReply) { if (que_ReplyMessages_WaitAndReply.Count > 0) { try { //replyMessage = listReplyMessages[RandomNumberGenerator.GenerateRandom(0, listReplyMessages.Count - 1)]; replyMessage = que_ReplyMessages_WaitAndReply.Dequeue(); } catch (Exception ex) { GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- locker_que_ReplyMessage_WaitAndReply -- --> " + ex.Message, Globals.Path_WaitNreplyErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- StartWaitAndReply() -- locker_que_ReplyMessage_WaitAndReply -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } } else { Log("[ " + DateTime.Now + " ] => [ All Loaded Reply Messages Used ]"); break; } } tweeter.Reply(ref globusHttpHelper, pgSrc_Profile, postAuthenticityToken, lst_Struct_TweetData[counterDataScraped].ID_Tweet, lst_Struct_TweetData[counterDataScraped].username__Tweet_User, replyMessage, out replyStatus); if (replyStatus == "posted") { counter_Reply++; clsDBQueryManager DataBase = new clsDBQueryManager(); string dbTweetMessage = StringEncoderDecoder.Encode(lst_Struct_TweetData[counterDataScraped].wholeTweetMessage); DataBase.InsertMessageData(Username, "Reply", lst_Struct_TweetData[counterDataScraped].ID_Tweet_User, lst_Struct_TweetData[counterDataScraped].wholeTweetMessage); Log("[ " + DateTime.Now + " ] => [ Replied : " + replyMessage + " by " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword + ":" + replyMessage, Globals.path_SuccessfullyRepliedAccounts); } else { counter_Reply++; Log("[ " + DateTime.Now + " ] => [ Couldn't Reply : " + replyMessage + " by " + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword + ":" + replyMessage, Globals.path_FailedRepliedAccounts); } //Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); //Thread.Sleep(interval); if (!waitAndReplyIsIntervalInsec) { Log("[ " + DateTime.Now + " ] => [ Delay For : " + TimeSpan.FromMilliseconds(interval).Minutes + " Minutes ]"); Thread.Sleep(interval); } else { try { interval = RandomNumberGenerator.GenerateRandom(waitAndReplyMinInterval, waitAndReplyMaxInterval); } catch { } Log("[ " + DateTime.Now + " ] => [ Delay For : " + interval + " seconds. ]"); interval = interval * 1000; Thread.Sleep(interval); } counterDataScraped++; if (countTweetsSent <= noOfTweetsPerReply) { countTweetsSent = 0; break; } } } else { Log("[ " + DateTime.Now + " ] => [ Tweet Data is not available for Tweet Keyword:- " + tweetKeyword + " ]"); } } if (que_ReplyMessages_WaitAndReply.Count <= 0) { Log("[ " + DateTime.Now + " ] => [ Remaining Reply Message : " + que_ReplyMessages_WaitAndReply.Count + " ]"); Log("[ " + DateTime.Now + " ] => [ Finished Reply Messages ]"); Log("------------------------------------------------------------------------------------------------------------------------------------------"); } if (que_TweetMessages_WaitAndReply.Count <= 0) { Log("[ " + DateTime.Now + " ] => [ Remaining Tweet Message: " + que_TweetMessages_WaitAndReply.Count + " ]"); Log("[ " + DateTime.Now + " ] => [ Finished Tweet Messages ]"); Log("------------------------------------------------------------------------------------------------------------------------------------------"); } //Log("Finished Replying with : " + Username); } } else { Log("[ " + DateTime.Now + " ] => [ Couldn't log in with :" + Username + " ]"); GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedLoginAccounts); } } catch (Exception ex) { //Log("[ " + DateTime.Now + " ] => [ >>Error :- TweetAccountManager (StartWaitAndReply)>> " + ex.Message + " ]"); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- StartWaitAndReply --> " + ex.Message, Globals.Path_WaitNreplyErroLog); GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager -- StartWaitAndReply() -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager); } }
public void StartFollowByKeyWord(Object Param) { try { try { Dic_Thread.Add(Thread.CurrentThread.Name, Thread.CurrentThread); } catch { }; Interlocked.Increment(ref counterThreadsFollowByKeyWord); //lockerThreadsFollowByKeyWord Array ParamArray = (Array)Param; string profileUsername = string.Empty; string profileUserpass = string.Empty; int FollowLimitCounter = 0; //int AccountCounter = 0; TweetAccountManager TweetAccountManager = new TweetAccountManager(); TwitterDataScrapper TwitterDataScrapper = new TwitterDataScrapper(); KeyValuePair<string, TweetAccountManager> item = (KeyValuePair<string, TweetAccountManager>)ParamArray.GetValue(0); int DelayStart = (int)ParamArray.GetValue(1); int DelayEnd = (int)ParamArray.GetValue(2); List<TwitterDataScrapper.StructTweetIDs> KeywordStructData = (List<TwitterDataScrapper.StructTweetIDs>)ParamArray.GetValue(3); profileUsername = item.Key; profileUserpass = item.Value.Password; //******search profile By keyWords string SeachKey = string.Empty; //List<TwitterDataScrapper.StructTweetIDs> KeywordStructData = new List<TwitterDataScrapper.StructTweetIDs>(); #region commented //if (FollowtweetKeywordList.Count != 0) //{ // TwitterDataScrapper.noOfRecords = int.Parse(txt_FollowByPerAccount.Text); // if (!chk_followbysinglekeywordperaccount.Checked) // { // try // { // if (searchkeywordqueue.Count == 0) // { // return; // } // SeachKey = searchkeywordqueue.Dequeue().ToString();//FollowtweetKeywordList[counterThreadsFollowByKeyWord]; // KeywordStructData = TwitterDataScrapper.GetTweetData_New(SeachKey); // if (KeywordStructData.Count == 0) // { // KeywordStructData = TwitterDataScrapper.NewKeywordStructData(SeachKey); // } // } // catch (Exception) // { // } // } // else // { // //TwitterDataScrapper.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); // foreach (string SeachKey_item in FollowtweetKeywordList) // { // List<TwitterDataScrapper.StructTweetIDs> KeywordStructData1 = new List<TwitterDataScrapper.StructTweetIDs>(); // int datacounter = 0; // KeywordStructData1 = TwitterDataScrapper.NewKeywordStructData1(SeachKey_item); // if (KeywordStructData1.Count == 0) // { // KeywordStructData1 = TwitterDataScrapper.KeywordStructData(SeachKey_item); // } // if (KeywordStructData1.Count == 0) // { // AddToLog_Follower("[ " + DateTime.Now + " ] => [ Key Word is not Exist/suspended. ]"); // } // foreach (var KeywordStructData1_item in KeywordStructData1) // { // if (datacounter == int.Parse(txt_FollowByPerAccount.Text)) // { // break; // } // else // { // KeywordStructData.Add(KeywordStructData1_item); // datacounter++; // } // } // } // } //} //else //{ // MessageBox.Show("Please Upload Keywords"); // //break; //} #endregion //************* try { if (KeywordStructData.Count > 0) { TweetAccountManager AccountManager = (TweetAccountManager)item.Value; AccountManager.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); if (!AccountManager.IsLoggedIn) { AccountManager.Login(); } if (!AccountManager.IsLoggedIn || !AccountManager.IsNotSuspended) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Not Logged in From Account = " + AccountManager.Username + " . ]"); return; } ///Return if Suspended if (AccountManager.AccountStatus == "Account Suspended") { AddToLog_Follower("[ " + DateTime.Now + " ] => [ " + profileUsername + " : Suspended ]"); return; } else if ((AccountManager.globusHttpHelper.gResponse.ResponseUri.ToString().ToLower()).Contains("captcha")) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ " + profileUsername + " : Asking for captcha. ]"); return; } foreach (var item1 in KeywordStructData) { if (!chk_followbysinglekeywordperaccount.Checked) { //accordint to get Follow users limits if (FollowLimitCounter >= (int.Parse(txt_FollowByPerAccount.Text))) { FollowLimitCounter = 0; break; } else { FollowLimitCounter++; } } //Get follow from user string AccountId = item1.ID_Tweet_User; //get Follow getFollowUserBySearch(new object[] { AccountManager, AccountId }); int Delay = RandomNumberGenerator.GenerateRandom((DelayStart * 1000), (DelayEnd * 1000)); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Delay :- " + TimeSpan.FromMilliseconds(Delay).Seconds + " Seconds. ]"); Thread.Sleep(Delay); } } else { //Message List is Empty //AddToLog_Follower("Key Word File is Empty or Wrong Formate"); //break; } } catch (Exception) { } } catch (Exception) { } finally { Interlocked.Decrement(ref counterThreadsFollowByKeyWord); lock (lockerThreadsFollowByKeyWord) { Monitor.Pulse(lockerThreadsFollowByKeyWord); } if (counterThreadsFollowByKeyWord == 0) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]"); AddToLog_Follower("-----------------------------------------------------------------------------------------------------------------------"); } } }
/// <summary> Get User details for While/blacklist User /// Get User details for While/blacklist User /// </summary> /// <param name="username">User Screan Name OR User ID</param> /// <returns>Details of Users</returns> /// #region Get User details for While/blacklist User //public static Dictionary<string, string> GetUserDetails(string username, out string status) //{ //// ChilkatHttpHelpr httpHelper = new ChilkatHttpHelpr(); // Dictionary<string, string> dataLst = new Dictionary<string, string>(); //// try //// { //// string PageSource = null; //// if (!string.IsNullOrEmpty(username) && NumberHelper.ValidateNumber(username)) //// { //// //PageSource = httpHelper.GetHtml("https://api.twitter.com/1/users/show.json?user_id=" + username + "&include_entities=true"); //// } //// else //// { //// //PageSource = httpHelper.GetHtml("https://api.twitter.com/1/users/show.json?screen_name=" + username + "&include_entities=true"); //// string url = string.Format("https://twitter.com/" + username); //// PageSource = httpHelper.GetHtml(url); //// } //// if (PageSource.Contains("error\":\"User has been suspended")) //// { //// status = "User has been suspended"; //// return dataLst; //// } //// else if (PageSource.Contains("message\":\"Sorry, that page does not exist")) //// { //// status = "Sorry, that page does not exist"; //// return dataLst; //// } //// else if (PageSource.Contains("Rate limit exceeded. Clients may not make more than 150 requests per hour.")) //// { //// status = "Rate limit exceeded. Clients may not make more than 150 requests per hour."; //// return dataLst; //// } //// if (!string.IsNullOrEmpty(PageSource)) //// { //// string id = string.Empty; //// string name = string.Empty; //// string screen_name = string.Empty; //// string location = string.Empty; //// string NoOfTweet = string.Empty; //// string followers_count = string.Empty; //// string friends_count = string.Empty; //// string profile_image_url = string.Empty; //// if (PageSource.Contains("data-user-id=")) //// { //// String[] getDataInArr = System.Text.RegularExpressions.Regex.Split(PageSource, "data-user-id="); //// if (getDataInArr.Count() > 0) //// { //// foreach (var item in getDataInArr) //// { //// int startindex = item.IndexOf("<strong>"); //// int endindex = item.IndexOf("</strong>"); ; //// NoOfTweet = item.Substring(startindex, endindex - startindex).Replace("<strong>", string.Empty).Replace(",", string.Empty); //// } //// } //// } //// if (PageSource.Contains("tweet_stats")) //// { //// String[] getDataInArr = System.Text.RegularExpressions.Regex.Split(PageSource, "tweet_stats"); //// if (getDataInArr.Count() > 0) //// { //// int startindex = getDataInArr[1].IndexOf("<strong>"); //// int endindex = getDataInArr[1].IndexOf("</strong>"); ; //// NoOfTweet = getDataInArr[1].Substring(startindex, endindex - startindex).Replace("<strong>", string.Empty).Replace(",", string.Empty); //// } //// } //// if (PageSource.Contains("following_stats")) //// { //// String[] getDataInArr = System.Text.RegularExpressions.Regex.Split(PageSource, "following_stats"); //// if (getDataInArr.Count() > 0) //// { //// int startindex = getDataInArr[1].IndexOf("<strong>"); //// int endindex = getDataInArr[1].IndexOf("</strong>"); ; //// friends_count = getDataInArr[1].Substring(startindex, endindex - startindex).Replace("<strong>", string.Empty).Replace(",", string.Empty); //// } //// } //// if (PageSource.Contains("follower_stats")) //// { //// String[] getDataInArr = System.Text.RegularExpressions.Regex.Split(PageSource, "follower_stats"); //// if (getDataInArr.Count() > 0) //// { //// int startindex = getDataInArr[1].IndexOf("<strong>"); //// int endindex = getDataInArr[1].IndexOf("</strong>"); //// followers_count = getDataInArr[1].Substring(startindex, endindex - startindex).Replace("<strong>", string.Empty).Replace(",", string.Empty); //// } //// } //// if (PageSource.Contains("data-url")) //// { //// String[] getDataInArr = System.Text.RegularExpressions.Regex.Split(PageSource, "data-url"); //// if (getDataInArr.Count() > 0) //// { //// int startindex = getDataInArr[1].IndexOf("=\""); //// int endindex = getDataInArr[1].IndexOf(">"); ; //// profile_image_url = getDataInArr[1].Substring(startindex, endindex - startindex).Replace("target=\"_blank", string.Empty).Replace("\"", string.Empty).Replace("=", string.Empty).Trim(); //// } //// } //// //string id = jobj["id"].ToString().Replace("\"", string.Empty); //// dataLst.Add("id", id); //// //string name = jobj["name"].ToString().Replace("\"", string.Empty); //// dataLst.Add("name", name); //// //string screen_name = jobj["screen_name"].ToString().Replace("\"", string.Empty); //// dataLst.Add("screen_name", screen_name); //// //string location = jobj["location"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("location", location); //// //string description = jobj["description"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("description", description); //// //string followers_count = jobj["followers_count"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("followers_count", followers_count); //// //string friends_count = jobj["friends_count"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("friends_count", friends_count); //// //string statuses_count = jobj["statuses_count"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("statuses_count", statuses_count); //// //string created_at = jobj["created_at"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("created_at", created_at); //// //string time_zone = jobj["time_zone"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("time_zone", time_zone); //// //string profile_image_url = jobj["profile_image_url"].ToString().Replace("\"", string.Empty); //// //dataLst.Add("profile_image_url", profile_image_url); //// } //// } //// catch (Exception ex) //// { //// Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> GetPhotoFromUsername() -- " + username + " --> " + ex.Message, Globals.Path_TwitterDataScrapper); //// Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> GetPhotoFromUsername() -- " + username + " --> " + ex.Message, Globals.Path_TwtErrorLogs); //// } //// //Assign Status // status = "Ok"; // return dataLst; //} public static Dictionary<string, string> GetUserDetails(string username, out string status) { TwitterDataScrapper twiterDataScrapper = new TwitterDataScrapper(); Dictionary<string, string> dataLst = new Dictionary<string, string>(); string id = string.Empty; string name = string.Empty; string screen_name = string.Empty; string location = string.Empty; string description = string.Empty; string NoOfTweet = string.Empty; string followers_count = string.Empty; string following_count = string.Empty; string profile_image_url = string.Empty; //string ProfileName = string.Empty; //string Location = string.Empty; //string Bio = string.Empty; string website = string.Empty; //string NoOfTweets = string.Empty; //string Followers = string.Empty; //string Followings = string.Empty; //try //{ ChilkatHttpHelpr objChilkat = new ChilkatHttpHelpr(); GlobusHttpHelper HttpHelper = new GlobusHttpHelper(); string ProfilePageSource = HttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + username), "", ""); string Responce = ProfilePageSource; #region Convert HTML to XML string xHtml = objChilkat.ConvertHtmlToXml(Responce); Chilkat.Xml xml = new Chilkat.Xml(); xml.LoadXml(xHtml); Chilkat.Xml xNode = default(Chilkat.Xml); Chilkat.Xml xBeginSearchAfter = default(Chilkat.Xml); #endregion //Get User Id From page if (!(ProfilePageSource == null)) { if (ProfilePageSource.Contains("data-user-id=")) { try { String[] getDataInArr = System.Text.RegularExpressions.Regex.Split(ProfilePageSource, "data-user-id="); if (getDataInArr.Count() > 0) { foreach (var item in getDataInArr) { if (item.Contains("<h1")) { int startindex = (1); int endindex = item.IndexOf(">") - 1; ; id = item.Substring(startindex, endindex - startindex).Replace("<strong>", string.Empty).Replace(",", string.Empty); if (id.Contains("\n")) { string[] arr =System.Text.RegularExpressions.Regex.Split(id,"\""); id=arr[0]; } dataLst.Add("id", id); break; } } //whiteListedUserCount++; } } catch (Exception) { } } } //else //{ // blackListedUserCount++; //} int counterdata = 0; xBeginSearchAfter = null; string dataDescription = string.Empty; xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNameTruncated-link u-textInheritColor js-nav js-action-profile-name");//"profile-field"); while ((xNode != null)) { try { string str = xNode.GetXml(); xBeginSearchAfter = xNode; if (counterdata == 1) { website = xNode.AccumulateTagContent("text", "script|style"); counterdata++; } else if (counterdata == 0) { name = xNode.AccumulateTagContent("text", "script|style"); dataLst.Add("name", name); counterdata++; } else { break; } xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNameTruncated-link u-textInheritColor js-nav js-action-profile-name");//"profile-field"); } catch (Exception) { } } //Get Screen name and ID xBeginSearchAfter = null; //string dataDescription = string.Empty; xNode = xml.SearchForAttribute(xBeginSearchAfter, "span", "class", "u-linkComplex-target"); while ((xNode != null)) { string str = xNode.GetXml(); xBeginSearchAfter = xNode; screen_name = xNode.AccumulateTagContent("text", "script|style").Replace("@", string.Empty); dataLst.Add("screen_name", screen_name); break; } xBeginSearchAfter = null; xNode = xml.SearchForAttribute(xBeginSearchAfter, "span", "class", "ProfileHeaderCard-locationText u-dir");//"location profile-field"); while ((xNode != null)) { xBeginSearchAfter = xNode; location = xNode.AccumulateTagContent("text", "script|style"); dataLst.Add("location", location); break; } xBeginSearchAfter = null; dataDescription = string.Empty; xNode = xml.SearchForAttribute(xBeginSearchAfter, "p", "class", "ProfileHeaderCard-bio u-dir"); while ((xNode != null)) { xBeginSearchAfter = xNode; description = xNode.AccumulateTagContent("text", "script|style"); dataLst.Add("description", description); break; } int counterData = 0; xBeginSearchAfter = null; xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-nav"); xBeginSearchAfter = xNode; if (counterData == 0) { NoOfTweet = xNode.AccumulateTagContent("text", "script|style").Replace("Tweets", string.Empty).Replace(",", string.Empty).Replace("Tweet",string.Empty); dataLst.Add("statuses_count", NoOfTweet); counterData++; } //dataDescription = string.Empty; xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-openSignupDialog js-nonNavigable u-textUserColor"); xBeginSearchAfter = xNode; if (counterData == 1) { following_count = xNode.AccumulateTagContent("text", "script|style").Replace(" Following", string.Empty).Replace(",", string.Empty).Replace("Following", string.Empty); dataLst.Add("friends_count", following_count); counterData++; } xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-openSignupDialog js-nonNavigable u-textUserColor"); //while ((xNode != null)) //{ // //xBeginSearchAfter = xNode; //if (counterData == 0) //{ // NoOfTweet = xNode.AccumulateTagContent("text", "script|style").Replace("Tweets", string.Empty).Replace(",", string.Empty).Replace("Tweet",string.Empty); // dataLst.Add("statuses_count", NoOfTweet); // counterData++; //} xBeginSearchAfter = xNode; if (counterData == 2) { followers_count = xNode.AccumulateTagContent("text", "script|style").Replace("Followers", string.Empty).Replace(",", string.Empty).Replace("Follower", string.Empty); dataLst.Add("followers_count", followers_count); counterData++; } //else //{ // break; //} xNode = xml.SearchForAttribute(xBeginSearchAfter, "a", "class", "ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-nav");//"js-nav"); // } status = "Ok"; //} //catch (Exception) //{ // status = ""; //} return dataLst; }
private void ScrapeMemberSeacrh() { try { lstIsStopScrapMember.Add(Thread.CurrentThread); lstIsStopScrapMember.Distinct(); Thread.CurrentThread.IsBackground = true; } catch { } try { TwitterDataScrapper TweetData = new TwitterDataScrapper(); txtlimitScrapeUsers.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txtlimitScrapeUsers.Text.Trim()) && NumberHelper.ValidateNumber(txtlimitScrapeUsers.Text.Trim())) { noOfRecords = Convert.ToInt32(txtlimitScrapeUsers.Text.Trim()); if (noOfRecords == 0) { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Do not put Zero value ]"); AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Default number of records is 50 ]"); noOfRecords = 50; } } else { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ please enter value in number of users ]"); return; } })); AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Scraping User INfo ]"); if (!chkUserInfo.Checked) foreach (string item in lstUrl) { if (!item.Contains("https://twitter.com")) { AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ You have entered invalid URL " + item + "]"); continue; } List<string> lstMember = new List<string>(); string returnStatus = string.Empty; lstMember = GetMembers(item, out returnStatus); AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ Scraped Member for Url " + item + "]"); } else { foreach (string item in lstUrl) { Thread scrapinfo = new Thread(scrapUserInfo); scrapinfo.Start(new object[] { item }); Thread.Sleep(200); } } //AddToLog_ScrapMember("[ " + DateTime.Now + " ] => [ process completed ]"); } catch { } }