Hack Forums
[C#] Instagram bot time follow automatization - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Instagram bot time follow automatization (/showthread.php?tid=5766935)



Instagram bot time follow automatization - itcorp - Dec 12, 2017

I need an idea for a better way,solution to follow 60 instagram user by two period.... 1 user per 1 min or 60 users peer 1 hour with deley of one hour..And is there a possibility to add cancellation token to webrequest?

This is my current solution


Collections
Code
       private List<InstaXDB.Modeli.Node> instagram_nods = Logika.SharedLogika().GetNods();
       private List<InstaXDB.Modeli.Node> GetNodes(int numberOfNods)
       {
           return instagram_nods.Where(n => n.followed_by_instaX == false).Take(numberOfNods).ToList();
       }

Logic

Code
       public async Task StartCampaing(CancellationToken token)
        {
            while (instagram_nods.Count() != 0 || !token.IsCancellationRequested)
            {
                try
                {

                    var filteredNods = GetNodes(60);
                    
                    foreach (var inst_nod in filteredNods)
                    {
                        
                        Logika.SharedLogika().MarkAsFollowedDB(inst_nod.username);

                        //Remove temp
                        Console.WriteLine("folow:" + inst_nod.username);

                        instagram_nods.Remove(inst_nod);
                        //follow user on each min
                        
                        await Task.Delay(TimeSpan.FromMinutes(1));

                        if (token.IsCancellationRequested)
                            Console.WriteLine("Loop per Canseled requested");
                            break;
                    }

                    if (token.IsCancellationRequested)
                    {
                        Console.WriteLine("Main loop Canseled requested");
                        break;
                    }

                    //follow 60 user on each hour
                    await Task.Delay(TimeSpan.FromHours(1));
                    
                }
                catch (OperationCanceledException)
                {
                  
                }
            }
        }

Thanks in advance


RE: Instagram bot time follow automatization - Ninja - Dec 12, 2017

You can do something like this:
Code
HttpWebRequest request = WebRequest.CreateHttp("google.com");
IAsyncResult result = request.BeginGetResponse();

while(!result.AsyncWaitHandle.WaitOne(100))
{
    if(token.IsCancellationRequested)
    {
        //do whatever
    }
}

using(HttpWebResponse response = request.EndGetResponse(result) as HttpWebResponse) { ... }

This will check every 100 milliseconds if the result is completed.
I wrote this code from heart real quick so I might have made a mistake somewhere.


RE: Instagram bot time follow automatization - itcorp - Dec 12, 2017

(Dec 12, 2017 09:03 AM)Ninja Wrote:  You can do something like this:
Code
HttpWebRequest request = WebRequest.CreateHttp("google.com");
IAsyncResult result = request.BeginGetResponse();

while(!result.AsyncWaitHandle.WaitOne(100))
{
   if(token.IsCancellationRequested)
   {
       //do whatever
   }
}

using(HttpWebResponse response = request.EndGetResponse(result) as HttpWebResponse) { ... }

This will check every 100 milliseconds if the result is completed.
I wrote this code from heart real quick so I might have made a mistake somewhere.

Thanks for reply..I will definitely try it...thanks again