Facebook
From Torrid Finch, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 66
  1. using Newtonsoft.Json;
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Chrome;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Runtime.InteropServices;
  12. using System.Security.Cryptography;
  13. using System.Text;
  14. using System.Threading;
  15.  
  16. namespace ConsoleApp1
  17. {
  18.  
  19.     class Program
  20.     {
  21.         //hide console
  22.         [DllImport("kernel32.dll")]
  23.         static extern IntPtr GetConsoleWindow();
  24.  
  25.         [DllImport("user32.dll")]
  26.         static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  27.  
  28.         const int SW_HIDE = 0;
  29.  
  30.  
  31.         static string json10 = File.ReadAllText(@"findElement.json");
  32.         static dynamic path = JsonConvert.DeserializeObject(json10);
  33.  
  34.  
  35.         static Random rnd = new Random();
  36.  
  37.         static ChromeDriver driver;
  38.  
  39.  
  40.         static string randomComm()
  41.         {
  42.             string json = File.ReadAllText(@"config/data.json");
  43.             dynamic data = JsonConvert.DeserializeObject(json);
  44.  
  45.             string json1 = File.ReadAllText(@"config/commentData.json");
  46.             dynamic comment = JsonConvert.DeserializeObject(json1);
  47.            
  48.             int i = 0;
  49.             Random rnd = new Random();
  50.             string x = "";
  51.             int lastComment = data["lastComment"];
  52.             while (x.Length < 2)
  53.             {
  54.                 string json2 = File.ReadAllText(@"config/data.json");
  55.                 dynamic data2 = JsonConvert.DeserializeObject(json2);
  56.  
  57.                 string commNumbers = data2["commentNumbers"];
  58.                 int randomNumber = rnd.Next(1, Int32.Parse(commNumbers));
  59.                 x = comment["comment_id_" + randomNumber];
  60.                 if (x.Length != 0 && lastComment != randomNumber)
  61.                 {
  62.  
  63.                    
  64.                     data2["lastComment"] = randomNumber;
  65.                     string output2 = JsonConvert.SerializeObject(data2, Formatting.Indented);
  66.                     File.WriteAllText(@"config/data.json", output2);
  67.                    
  68.                    
  69.                     Console.WriteLine(x);
  70.                     return x;
  71.                    
  72.                 }
  73.                 i++;
  74.  
  75.             }
  76.             return "none";
  77.         }
  78.  
  79.  
  80.         static void clickElementByXpath(string name)
  81.         {
  82.             bool x = false;
  83.             while (x != true)
  84.             {
  85.                 if (x == true)
  86.                 {
  87.                     IWebElement y = driver.FindElement(By.XPath(name));
  88.                     y.Click();
  89.                     Console.WriteLine("Dostepny");
  90.                 }
  91.                 else
  92.                 {
  93.                     try
  94.                     {
  95.                         IWebElement y = driver.FindElement(By.XPath(name));
  96.                         y.Click();
  97.                         x = true;
  98.                         Console.WriteLine("Dostepny");
  99.                     }
  100.  
  101.                     catch
  102.                     {
  103.                         Console.WriteLine("Nie dostepny");
  104.                         Thread.Sleep(200);
  105.                     }
  106.                 }
  107.             }
  108.             Thread.Sleep(500);
  109.         }
  110.  
  111.         static void sendKeysByName(string name, string message)
  112.         {
  113.  
  114.             bool x = false;
  115.             while (x != true)
  116.             {
  117.                 if (x == true)
  118.                 {
  119.                     IWebElement y = driver.FindElement(By.Name(name));
  120.                     y.SendKeys(message);
  121.                     Console.WriteLine("Dostepny");
  122.                 }
  123.                 else
  124.                 {
  125.                     try
  126.                     {
  127.                         IWebElement y = driver.FindElement(By.Name(name));
  128.                         y.SendKeys(message); ;
  129.                         x = true;
  130.                         Console.WriteLine("Dostepny");
  131.                     }
  132.  
  133.                     catch
  134.                     {
  135.                         Console.WriteLine("Nie dostepny");
  136.                         Thread.Sleep(200);
  137.  
  138.                     }
  139.                 }
  140.  
  141.             }
  142.             Thread.Sleep(500);
  143.         }
  144.  
  145.         static bool clickElementByXpath2(string name)
  146.         {
  147.             int z = 0;
  148.             bool x = false;
  149.             while (x != true)
  150.             {
  151.                 if (x == true)
  152.                 {
  153.                     IWebElement y = driver.FindElement(By.XPath(name));
  154.  
  155.                     Console.WriteLine("Dostepny");
  156.                     return false;
  157.                 }
  158.                 else
  159.                 {
  160.                     try
  161.                     {
  162.                         IWebElement y = driver.FindElement(By.XPath(name));
  163.                         y.Click();
  164.                         x = true;
  165.                         Console.WriteLine("Dostepny");
  166.                         return false;
  167.                     }
  168.  
  169.                     catch
  170.                     {
  171.                         Console.WriteLine("Nie dostepny");
  172.                         Thread.Sleep(200);
  173.                         z++;
  174.  
  175.                     }
  176.                 }
  177.                 if (z >= 15)
  178.                 {
  179.                     return true;
  180.                 }
  181.             }
  182.             Thread.Sleep(500);
  183.             return true;
  184.         }
  185.  
  186.         static void clickElementByClassName(string name)
  187.         {
  188.             bool x = false;
  189.             while (x != true)
  190.             {
  191.                 if (x == true)
  192.                 {
  193.                     IWebElement y = driver.FindElement(By.ClassName(name));
  194.                     y.Click();
  195.                     Console.WriteLine("Dostepny");
  196.                 }
  197.                 else
  198.                 {
  199.                     try
  200.                     {
  201.                         IWebElement y = driver.FindElement(By.ClassName(name));
  202.                         y.Click();
  203.                         x = true;
  204.                         Console.WriteLine("Dostepny");
  205.                     }
  206.  
  207.                     catch
  208.                     {
  209.                         Console.WriteLine("Nie dostepny");
  210.                         Thread.Sleep(200);
  211.                     }
  212.                 }
  213.             }
  214.             Thread.Sleep(500);
  215.         }
  216.  
  217.         static void sendKeysByXpath(string name, string message)
  218.         {
  219.  
  220.             bool x = false;
  221.             while (x != true)
  222.             {
  223.                 if (x == true)
  224.                 {
  225.                     IWebElement y = driver.FindElement(By.XPath(name));
  226.                     y.SendKeys(message);
  227.                     Console.WriteLine("Dostepny");
  228.                 }
  229.                 else
  230.                 {
  231.                     try
  232.                     {
  233.                         IWebElement y = driver.FindElement(By.XPath(name));
  234.                         y.SendKeys(message); ;
  235.                         x = true;
  236.                         Console.WriteLine("Dostepny");
  237.                     }
  238.  
  239.                     catch
  240.                     {
  241.                         Console.WriteLine("Nie dostepny");
  242.                         Thread.Sleep(200);
  243.  
  244.                     }
  245.                 }
  246.  
  247.             }
  248.             Thread.Sleep(500);
  249.         }
  250.  
  251.         static void sendKeysById(string name, string message)
  252.         {
  253.  
  254.             bool x = false;
  255.             while (x != true)
  256.             {
  257.                 if (x == true)
  258.                 {
  259.                     IWebElement y = driver.FindElement(By.Id(name));
  260.                     y.SendKeys(message);
  261.                     Console.WriteLine("Dostepny");
  262.                 }
  263.                 else
  264.                 {
  265.                     try
  266.                     {
  267.                         IWebElement y = driver.FindElement(By.Id(name));
  268.                         y.SendKeys(message); ;
  269.                         x = true;
  270.                         Console.WriteLine("Dostepny");
  271.                     }
  272.  
  273.                     catch
  274.                     {
  275.                         Console.WriteLine("Nie dostepny");
  276.                         Thread.Sleep(200);
  277.  
  278.                     }
  279.                 }
  280.  
  281.             }
  282.             Thread.Sleep(500);
  283.         }
  284.  
  285.         static string getAttributeByXpath(string name, string kindfOfAttribute)
  286.         {
  287.             bool x = false;
  288.             while (x != true)
  289.             {
  290.                 if (x == true)
  291.                 {
  292.                     string y = driver.FindElement(By.XPath(name)).GetAttribute(kindfOfAttribute);
  293.  
  294.                     Console.WriteLine("Dostepny");
  295.                     return y;
  296.                 }
  297.                 else
  298.                 {
  299.                     try
  300.                     {
  301.                         string y = driver.FindElement(By.XPath(name)).GetAttribute(kindfOfAttribute);
  302.  
  303.                         x = true;
  304.                         Console.WriteLine("Dostepny");
  305.                         return y;
  306.                     }
  307.  
  308.                     catch
  309.                     {
  310.                         Console.WriteLine("Nie dostepny");
  311.                         Thread.Sleep(200);
  312.                     }
  313.                 }
  314.             }
  315.             Thread.Sleep(500);
  316.             return "done";
  317.         }
  318.  
  319.         static string getAttributeByCssSelector(string name, string kindfOfAttribute)
  320.         {
  321.             bool x = false;
  322.             while (x != true)
  323.             {
  324.                 if (x == true)
  325.                 {
  326.                     string y = driver.FindElement(By.CssSelector(name)).GetAttribute(kindfOfAttribute);
  327.  
  328.                     Console.WriteLine("Dostepny");
  329.                     return y;
  330.                 }
  331.                 else
  332.                 {
  333.                     try
  334.                     {
  335.                         string y = driver.FindElement(By.CssSelector(name)).GetAttribute(kindfOfAttribute);
  336.  
  337.                         x = true;
  338.                         Console.WriteLine("Dostepny");
  339.                         return y;
  340.                     }
  341.  
  342.                     catch
  343.                     {
  344.                         Console.WriteLine("Nie dostepny");
  345.                         Thread.Sleep(200);
  346.                     }
  347.                 }
  348.             }
  349.             Thread.Sleep(500);
  350.             return "done";
  351.         }
  352.  
  353.         static string getAttributeByCssSelector2(string name, string kindfOfAttribute)
  354.         {
  355.             int z = 0;
  356.             bool x = false;
  357.             while (x != true)
  358.             {
  359.                 if (x == true)
  360.                 {
  361.                     string y = driver.FindElement(By.CssSelector(name)).GetAttribute(kindfOfAttribute);
  362.  
  363.                     Console.WriteLine("Dostepny");
  364.                     return y;
  365.                 }
  366.                 else
  367.                 {
  368.                     try
  369.                     {
  370.                         string y = driver.FindElement(By.CssSelector(name)).GetAttribute(kindfOfAttribute);
  371.  
  372.                         x = true;
  373.                         Console.WriteLine("Dostepny");
  374.                         return y;
  375.                     }
  376.  
  377.                     catch
  378.                     {
  379.                         z++;
  380.                         Console.WriteLine("Nie dostepny");
  381.                         Thread.Sleep(200);
  382.                     }
  383.                 }
  384.                 if (z >= 5)
  385.                 {
  386.                     return "false";
  387.                 }
  388.             }
  389.             Thread.Sleep(500);
  390.             return "done";
  391.         }
  392.  
  393.         static string checkElementByXpath(string name)
  394.         {
  395.             int z = 0;
  396.             bool x = false;
  397.             while (x != true)
  398.             {
  399.                 if (x == true)
  400.                 {
  401.                     IWebElement y = driver.FindElement(By.XPath(name));
  402.  
  403.                     Console.WriteLine("Dostepny");
  404.                     return "true";
  405.                 }
  406.                 else
  407.                 {
  408.                     try
  409.                     {
  410.                         IWebElement y = driver.FindElement(By.XPath(name));
  411.  
  412.                         x = true;
  413.                         Console.WriteLine("Dostepny");
  414.                         return "true";
  415.                     }
  416.  
  417.                     catch
  418.                     {
  419.                         Console.WriteLine("Nie dostepny");
  420.                         Thread.Sleep(200);
  421.  
  422.                         z++;
  423.  
  424.                     }
  425.                 }
  426.                 if (z >= 10)
  427.                 {
  428.                     return "false";
  429.                 }
  430.             }
  431.             Thread.Sleep(500);
  432.             return "done";
  433.         }
  434.  
  435.         static string checkElementByXpath2(string name)
  436.         {
  437.             int z = 0;
  438.             bool x = false;
  439.             while (x != true)
  440.             {
  441.                 if (x == true)
  442.                 {
  443.                     IWebElement y = driver.FindElement(By.XPath(name));
  444.  
  445.                     Console.WriteLine("Dostepny");
  446.                     return "false";
  447.                 }
  448.                 else
  449.                 {
  450.                     try
  451.                     {
  452.                         IWebElement y = driver.FindElement(By.XPath(name));
  453.  
  454.                         x = true;
  455.                         Console.WriteLine("Dostepny");
  456.                         return "false";
  457.                     }
  458.  
  459.                     catch
  460.                     {
  461.                         Console.WriteLine("Nie dostepny");
  462.                         Thread.Sleep(200);
  463.  
  464.                         z++;
  465.  
  466.                     }
  467.                 }
  468.                 if (z >= 2)
  469.                 {
  470.                     return "true";
  471.                 }
  472.             }
  473.             Thread.Sleep(500);
  474.             return "done";
  475.         }
  476.  
  477.         static string checkElementByXpath3(string name)
  478.         {
  479.             int z = 0;
  480.             bool x = false;
  481.             while (x != true)
  482.             {
  483.                 if (x == true)
  484.                 {
  485.                     IWebElement y = driver.FindElement(By.XPath(name));
  486.  
  487.                     Console.WriteLine("Dostepny");
  488.                     return "false";
  489.                 }
  490.                 else
  491.                 {
  492.                     try
  493.                     {
  494.                         IWebElement y = driver.FindElement(By.XPath(name));
  495.  
  496.                         x = true;
  497.                         Console.WriteLine("Dostepny");
  498.                         return "false";
  499.                     }
  500.  
  501.                     catch
  502.                     {
  503.                         Console.WriteLine("Nie dostepny");
  504.                         Thread.Sleep(200);
  505.  
  506.                         z++;
  507.  
  508.                     }
  509.                 }
  510.                 if (z >= 20)
  511.                 {
  512.                     return "true";
  513.                 }
  514.             }
  515.             Thread.Sleep(500);
  516.             return "done";
  517.         }
  518.  
  519.         static void useRandomTimeSafe()
  520.         {
  521.             Random rnd = new Random();
  522.             int time = rnd.Next(4000, 8000);
  523.  
  524.             Thread.Sleep(time);
  525.         }
  526.  
  527.         static void useRandomTimeFast()
  528.         {
  529.             Random rnd = new Random();
  530.             int time = rnd.Next(1433, 1833);
  531.  
  532.             Thread.Sleep(time);
  533.         }
  534.  
  535.         static void sendSmsCode()
  536.         {
  537.             int smsCode = 0;
  538.  
  539.             while (smsCode == 0)
  540.             {
  541.                 string json = File.ReadAllText(@"codeSms.json");
  542.                 dynamic code = JsonConvert.DeserializeObject(json);
  543.                 smsCode = code["code"];
  544.                 if (smsCode != 0)
  545.                 {
  546.  
  547.                     Thread.Sleep(1000);
  548.                     try
  549.                     {
  550.                         IWebElement panel = driver.FindElement(By.XPath("//input[@class='_2hvTZ pexuQ zyHYP']"));
  551.                         panel.SendKeys(smsCode.ToString());
  552.                     }
  553.                     catch
  554.                     {
  555.                         string smsCodeInput = path["smsCodeInput"];
  556.                         sendKeysByXpath(smsCodeInput, smsCode.ToString());
  557.                     }
  558.  
  559.                     string smsCodeAcceptButton = path["smsCodeAcceptButton"];
  560.                     clickElementByXpath(smsCodeAcceptButton);
  561.                     Thread.Sleep(2000);
  562.  
  563.  
  564.                     int codeError = driver.FindElements(By.Id("twoFactorErrorAlert")).Count();
  565.                     if (codeError == 0)
  566.                     {
  567.                         code["code"] = 0;
  568.                         code["codeError"] = false;
  569.                         string output = JsonConvert.SerializeObject(code, Formatting.Indented);
  570.                         File.WriteAllText(@"codeSms.json", output);
  571.                     }
  572.                     else
  573.                     {
  574.                         code["code"] = 0;
  575.                         code["codeError"] = true;
  576.                         string output = JsonConvert.SerializeObject(code, Formatting.Indented);
  577.                         File.WriteAllText(@"codeSms.json", output);
  578.  
  579.                         Thread.Sleep(2000);
  580.  
  581.  
  582.  
  583.                         driver.Close();
  584.                         driver.Quit();
  585.                         Environment.Exit(0);
  586.                     }
  587.  
  588.  
  589.                 }
  590.                 else
  591.                 {
  592.                     Thread.Sleep(10000);
  593.                 }
  594.             }
  595.  
  596.         }
  597.  
  598.  
  599.         static void webBrowser()
  600.         {
  601.             /*
  602.             var chromeOptions = new ChromeOptions();
  603.            ChromeDriverService service = ChromeDriverService.CreateDefaultService();
  604.             service.HideCommandPromptWindow = true;
  605.             chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
  606.             chromeOptions.AddExcludedArgument("enable-automation");
  607.             chromeOptions.AddArguments("--incognito");
  608.             chromeOptions.AddArguments("network.cookie.cookieBehavior");
  609.  
  610.             chromeOptions.AddArgument("headless");
  611.             */
  612.  
  613.             ChromeDriverService service = ChromeDriverService.CreateDefaultService();
  614.             service.HideCommandPromptWindow = true;
  615.  
  616.             var options = new ChromeOptions();
  617.  
  618.             //options.AddArgument("--window-position=-32000,-32000");
  619.            
  620.  
  621.             options.AddExcludedArgument("enable-automation");
  622.             options.AddArguments("incognito");
  623.             options.AddAdditionalCapability("useAutomationExtension", false);
  624.             options.AddArgument("headless");
  625.             driver = new ChromeDriver(service, options);
  626.  
  627.             driver.Navigate().GoToUrl("https://www.instagram.com/accounts/login/?hl=pl");
  628.             Thread.Sleep(5000);
  629.  
  630.             driver.Manage().Window.Size = new Size(1200, 600);
  631.         }
  632.  
  633.         static void loginAsInstagram()
  634.         {
  635.             string json2 = File.ReadAllText(@"neutralData.json");
  636.             dynamic neutralData = JsonConvert.DeserializeObject(json2);
  637.             string email = neutralData["email"];
  638.             string password = neutralData["password"];
  639.  
  640.             string instagramEmail = path["instagramEmail"];
  641.             sendKeysByName(instagramEmail, Decrypt(email));
  642.             Thread.Sleep(1000);
  643.  
  644.             string instagramPassword = path["instagramPassword"];
  645.             sendKeysByName(instagramPassword, Decrypt(password));
  646.  
  647.             string instagramLoginButton = path["instagramLoginButton"];
  648.             clickElementByXpath(instagramLoginButton);
  649.  
  650.             string smsPanel = path["smsPanel"];
  651.             bool smsCode = clickElementByXpath2(smsPanel);
  652.  
  653.             // check sms verify
  654.             if (smsCode == true)
  655.             {
  656.                 string json = File.ReadAllText(@"neutralData.json");
  657.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  658.                 jsonObj["smsLogin"] = "ok";
  659.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  660.                 File.WriteAllText(@"neutralData.json", output);
  661.             }
  662.             if (smsCode == false)
  663.             {
  664.                 string json = File.ReadAllText(@"neutralData.json");
  665.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  666.                 jsonObj["smsLogin"] = "error";
  667.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  668.                 File.WriteAllText(@"neutralData.json", output);
  669.  
  670.                 Thread.Sleep(2000);
  671.  
  672.                 sendSmsCode();
  673.             }
  674.  
  675.  
  676.             string instagramLoginError = path["instagramLoginError"];
  677.             bool error = clickElementByXpath2(instagramLoginError);
  678.             if (error == true)
  679.             {
  680.                 string json = File.ReadAllText(@"neutralData.json");
  681.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  682.                 jsonObj["errorLogin"] = "ok";
  683.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  684.                 File.WriteAllText(@"neutralData.json", output);
  685.  
  686.                 string json1 = File.ReadAllText(@"neutralData.json");
  687.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  688.                 neutral["loginSucces"] = true;
  689.                 string output2 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  690.                 File.WriteAllText(@"neutralData.json", output2);
  691.             }
  692.             if (error == false)
  693.             {
  694.                 string json = File.ReadAllText(@"neutralData.json");
  695.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  696.                 jsonObj["errorLogin"] = "error";
  697.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  698.                 File.WriteAllText(@"neutralData.json", output);
  699.  
  700.  
  701.                 string json1 = File.ReadAllText(@"neutralData.json");
  702.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  703.                 neutral["tryToLogin"] = false;
  704.                 string output2 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  705.                 File.WriteAllText(@"neutralData.json", output2);
  706.  
  707.                 Thread.Sleep(2000);
  708.             }
  709.  
  710.         }
  711.  
  712.         static void loginAsFacebook()
  713.         {
  714.             string json2 = File.ReadAllText(@"neutralData.json");
  715.             dynamic neutralData = JsonConvert.DeserializeObject(json2);
  716.  
  717.             string facebookLoginPanel = path["facebookLoginPanel"];
  718.             clickElementByXpath(facebookLoginPanel);
  719.  
  720.             string email = neutralData["email"];
  721.             string password = neutralData["password"];
  722.  
  723.             string facebookEmail = path["facebookEmail"];
  724.             sendKeysById(facebookEmail, Decrypt(email));
  725.  
  726.             Thread.Sleep(1000);
  727.  
  728.             string facebookPassword = path["facebookPassword"];
  729.             sendKeysById(facebookPassword, Decrypt(password));
  730.  
  731.             string facebookLoginButton = path["facebookLoginButton"];
  732.             clickElementByXpath(facebookLoginButton);
  733.             ///////////////////error find
  734.  
  735.             string smsPanel = path["smsPanel"];
  736.             bool smsCode = clickElementByXpath2(smsPanel);
  737.  
  738.             // check sms verify
  739.             if (smsCode == true)
  740.             {
  741.                 string json = File.ReadAllText(@"neutralData.json");
  742.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  743.                 jsonObj["smsLogin"] = "ok";
  744.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  745.                 File.WriteAllText(@"neutralData.json", output);
  746.             }
  747.             if (smsCode == false)
  748.             {
  749.                 string json = File.ReadAllText(@"neutralData.json");
  750.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  751.                 jsonObj["smsLogin"] = "error";
  752.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  753.                 File.WriteAllText(@"neutralData.json", output);
  754.  
  755.                 Thread.Sleep(2000);
  756.  
  757.                 sendSmsCode();
  758.             }
  759.  
  760.             string facebookLoginError = path["facebookLoginError"];
  761.             bool error = clickElementByXpath2(facebookLoginError);
  762.             if (error == true)
  763.             {
  764.                 string json = File.ReadAllText(@"neutralData.json");
  765.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  766.                 jsonObj["errorLogin"] = "ok";
  767.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  768.                 File.WriteAllText(@"neutralData.json", output);
  769.  
  770.                 string json1 = File.ReadAllText(@"neutralData.json");
  771.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  772.                 neutral["loginSucces"] = true;
  773.                 string output2 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  774.                 File.WriteAllText(@"neutralData.json", output2);
  775.             }
  776.             if (error == false)
  777.             {
  778.                 string json = File.ReadAllText(@"neutralData.json");
  779.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  780.                 jsonObj["errorLogin"] = "error";
  781.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  782.                 File.WriteAllText(@"neutralData.json", output);
  783.  
  784.  
  785.                 string json1 = File.ReadAllText(@"neutralData.json");
  786.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  787.                 neutral["tryToLogin"] = false;
  788.                 string output2 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  789.                 File.WriteAllText(@"neutralData.json", output2);
  790.  
  791.                 Thread.Sleep(2000);
  792.             }
  793.             string acceptFacbeookLoginAccount = path["acceptFacbeookLoginAccount"];
  794.             string statusAcceptFbButton = checkElementByXpath2(acceptFacbeookLoginAccount);
  795.             if (statusAcceptFbButton.Equals("false"))
  796.             {
  797.                 clickElementByXpath(acceptFacbeookLoginAccount);
  798.             }
  799.  
  800.         }
  801.  
  802.         static void currentAction(string action)
  803.         {
  804.             string json2 = File.ReadAllText(@"action.json");
  805.             dynamic dat2 = JsonConvert.DeserializeObject(json2);
  806.             dat2["action"] = action;
  807.             string output = JsonConvert.SerializeObject(dat2, Formatting.Indented);
  808.             File.WriteAllText(@"action.json", output);
  809.  
  810.         }
  811.  
  812.         static void currentLoginStatus(int status)
  813.         {
  814.             string json2 = File.ReadAllText(@"neutralData.json");
  815.             dynamic dat2 = JsonConvert.DeserializeObject(json2);
  816.             dat2["loginProgress"] = status;
  817.             string output = JsonConvert.SerializeObject(dat2, Formatting.Indented);
  818.             File.WriteAllText(@"neutralData.json", output);
  819.  
  820.         }
  821.  
  822.         static void isLoginReady(bool status)
  823.         {
  824.             string json2 = File.ReadAllText(@"neutralData.json");
  825.             dynamic dat2 = JsonConvert.DeserializeObject(json2);
  826.             dat2["isLoginScreenReady"] = status;
  827.             string output = JsonConvert.SerializeObject(dat2, Formatting.Indented);
  828.             File.WriteAllText(@"neutralData.json", output);
  829.  
  830.         }
  831.  
  832.         static int dayLike()
  833.         {
  834.             string json2 = File.ReadAllText(@"config/likeDay.json");
  835.             dynamic like = JsonConvert.DeserializeObject(json2);
  836.             try
  837.             {
  838.                 string date = DateTime.Now.ToString("dd.MM.yyy");
  839.                 string list = like[date];
  840.                 string likeBeforeS = like[date];
  841.                 int likeBefore = Int32.Parse(likeBeforeS);
  842.                 return likeBefore;
  843.             }
  844.             catch
  845.             {
  846.                 return 0;
  847.             }
  848.         }
  849.  
  850.         static int dayProfileLike()
  851.         {
  852.             string json2 = File.ReadAllText(@"config/profileLikeDay.json");
  853.             dynamic like = JsonConvert.DeserializeObject(json2);
  854.             try
  855.             {
  856.                 string date = DateTime.Now.ToString("dd.MM.yyy");
  857.                 string list = like[date];
  858.                 string likeBeforeS = like[date];
  859.                 int likeBefore = Int32.Parse(likeBeforeS);
  860.                 return likeBefore;
  861.             }
  862.             catch
  863.             {
  864.                 return 0;
  865.             }
  866.         }
  867.  
  868.         static int dayComm()
  869.         {
  870.             string json2 = File.ReadAllText(@"config/commDay.json");
  871.             dynamic comm = JsonConvert.DeserializeObject(json2);
  872.             try
  873.             {
  874.                 string date = DateTime.Now.ToString("dd.MM.yyy");
  875.                 string list = comm[date];
  876.                 string likeBeforeS = comm[date];
  877.                 int likeBefore = Int32.Parse(likeBeforeS);
  878.                 return likeBefore;
  879.             }
  880.             catch
  881.             {
  882.                 return 0;
  883.             }
  884.         }
  885.  
  886.  
  887.  
  888.         static void Main(string[] args)
  889.         {
  890.             //hide console
  891.             //var handle = GetConsoleWindow();
  892.             // ShowWindow(handle, SW_HIDE);
  893.  
  894.             for(int i = 0; i <= 20; i++)
  895.             {
  896.                 randomComm();
  897.             }
  898.            
  899.            
  900.  
  901.             currentAction(" ");
  902.  
  903.             currentLoginStatus(0);
  904.             isLoginReady(false);
  905.  
  906.             string json = File.ReadAllText(@"codeSms.json");
  907.             dynamic code = JsonConvert.DeserializeObject(json);
  908.             code["codeError"] = false;
  909.             string output1 = JsonConvert.SerializeObject(code, Formatting.Indented);
  910.             File.WriteAllText(@"codeSms.json", output1);
  911.  
  912.             string json1 = File.ReadAllText(@"neutralData.json");
  913.             dynamic neutral = JsonConvert.DeserializeObject(json1);
  914.             neutral["neutralData"] = true;
  915.             neutral["tryToLogin"] = false;
  916.             neutral["runTheProgramm"] = false;
  917.             neutral["loginSucces"] = false;
  918.             neutral["loginStatus"] = false;
  919.             neutral["errorLogin"] = "ok";
  920.             neutral["smsLogin"] = "ok";
  921.             neutral["exitTheProgram"] = false;
  922.             string output2 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  923.             File.WriteAllText(@"neutralData.json", output2);
  924.  
  925.  
  926.             Thread.Sleep(4000);
  927.  
  928.  
  929.             List<Action> functions = new List<Action>();
  930.             functions.Add(getPostAndFollowesNumber);
  931.             functions.Add(accountAge);
  932.             functions.Add(kindOfProgramm);
  933.             functions.Add(getPostAndFollowesNumber);
  934.             functions.Add(likePostFromLink);
  935.             functions.Add(getPostAndFollowesNumber);
  936.  
  937.             if (codeCheck() == true)
  938.             {
  939.                 currentAction("Start working");
  940.                 webBrowser();
  941.                 logIn();
  942.                 getUserName();
  943.  
  944.                 bool exitProgram = neutral["exitTheProgram"];
  945.                 while (!exitProgram)
  946.                 {
  947.                     while (waitToStartTheProgramm())
  948.                     {
  949.  
  950.                         //clear json file and stats
  951.                         File.WriteAllText(@"config/linkToLike.json", "{}");
  952.                         string json5 = File.ReadAllText(@"config/data.json");
  953.                         dynamic jsonObj5 = JsonConvert.DeserializeObject(json5);
  954.                         jsonObj5["currentLike"] = 0.ToString();
  955.                         jsonObj5["currentFollow"] = 0.ToString();
  956.                         jsonObj5["currentComment"] = 0.ToString();
  957.                         jsonObj5["likesInAccountFromLinks"] = 0.ToString();
  958.                         jsonObj5["commError"] = 0.ToString();
  959.                         jsonObj5["igError"] = "false";
  960.                         jsonObj5["hashtagError"] = false;
  961.                         string output = JsonConvert.SerializeObject(jsonObj5, Formatting.Indented);
  962.                         File.WriteAllText(@"config/data.json", output);
  963.                         Thread.Sleep(1000);
  964.  
  965.                         foreach (Action func in functions)
  966.                         {
  967.                             string json50 = File.ReadAllText(@"neutralData.json");
  968.                             dynamic neutral1 = JsonConvert.DeserializeObject(json50);
  969.                             bool x = neutral1["exitTheProgram"];
  970.                             if (x == true)
  971.                                 break;
  972.                             func();
  973.                         }
  974.  
  975.                         //getPostAndFollowesNumber();
  976.  
  977.                         // accountAge();
  978.  
  979.                         //kindOfProgramm();
  980.  
  981.                         //getPostAndFollowesNumber();
  982.                         //likePostFromLink();
  983.  
  984.                         //getPostAndFollowesNumber();
  985.                         currentAction("Work finished");
  986.                         Thread.Sleep(3000);
  987.                         currentAction(" ");
  988.  
  989.                         neutral["runTheProgramm"] = false;
  990.                         neutral["exitTheProgram"] = false;
  991.                         string output500 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  992.                         File.WriteAllText(@"neutralData.json", output500);
  993.                     }
  994.                 }
  995.  
  996.  
  997.  
  998.  
  999.             }
  1000.             else
  1001.             {
  1002.                 Console.Clear();
  1003.                 Console.WriteLine("Wrong verify code, buy full version or contact with suport");
  1004.                 Console.WriteLine((DateTime.Now.DayOfYear * 2137 * DateTime.DaysInMonth(2001, 2)));
  1005.                 currentAction(" ");
  1006.                 Environment.Exit(0);
  1007.  
  1008.             }
  1009.             neutral["neutralData"] = false;
  1010.             string output3 = JsonConvert.SerializeObject(neutral, Formatting.Indented);
  1011.             File.WriteAllText(@"neutralData.json", output3);
  1012.             Console.WriteLine((DateTime.Now.DayOfYear * 2137 * DateTime.DaysInMonth(2001, 2)));
  1013.             driver.Close();
  1014.             driver.Quit();
  1015.             Thread.Sleep(1000);
  1016.             currentAction(" ");
  1017.             currentLoginStatus(0);
  1018.             isLoginReady(false);
  1019.             Environment.Exit(0);
  1020.  
  1021.  
  1022.         }
  1023.  
  1024.  
  1025.         static void hashatagError()
  1026.         {
  1027.             Thread.Sleep(2000);
  1028.             string noHastag = path["noHastag"];
  1029.             int hashtag = driver.FindElements(By.XPath(noHastag)).Count();
  1030.             if (hashtag != 0)
  1031.             {
  1032.                 string json5 = File.ReadAllText(@"config/data.json");
  1033.                 dynamic jsonObj5 = JsonConvert.DeserializeObject(json5);
  1034.                 jsonObj5["hashtagError"] = true;
  1035.                 string output = JsonConvert.SerializeObject(jsonObj5, Formatting.Indented);
  1036.                 File.WriteAllText(@"config/data.json", output);
  1037.                 Thread.Sleep(2000);
  1038.                 driver.Close();
  1039.                 driver.Quit();
  1040.                 Environment.Exit(0);
  1041.             }
  1042.         }
  1043.  
  1044.         static void waitToLogin()
  1045.         {
  1046.             bool x = false;
  1047.             while (x == false)
  1048.             {
  1049.                 string json1 = File.ReadAllText(@"neutralData.json");
  1050.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  1051.                 x = neutral["tryToLogin"];
  1052.                 if (x == false)
  1053.                 {
  1054.                     Thread.Sleep(4000);
  1055.                 }
  1056.             }
  1057.         }
  1058.  
  1059.         static bool waitToStartTheProgramm()
  1060.         {
  1061.             bool x = false;
  1062.             while (x == false)
  1063.             {
  1064.                 string json1 = File.ReadAllText(@"neutralData.json");
  1065.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  1066.                 x = neutral["runTheProgramm"];
  1067.                 if (x == false)
  1068.                 {
  1069.                     Thread.Sleep(4000);
  1070.  
  1071.                 }
  1072.                 if (x == true)
  1073.                 {
  1074.                     return true;
  1075.                 }
  1076.             }
  1077.             return false;
  1078.         }
  1079.  
  1080.  
  1081.  
  1082.  
  1083.         static void logIn()
  1084.         {
  1085.  
  1086.             bool loginSucces = false;
  1087.  
  1088.             while (loginSucces == false)
  1089.             {
  1090.                 isLoginReady(true);
  1091.                 waitToLogin();
  1092.  
  1093.                 string json = File.ReadAllText(@"neutralData.json");
  1094.                 dynamic neutralData = JsonConvert.DeserializeObject(json);
  1095.  
  1096.                 driver.Navigate().GoToUrl("https://www.instagram.com/accounts/login/?hl=pl");
  1097.  
  1098.                 currentLoginStatus(1);
  1099.                 currentAction("Try To Log In");
  1100.  
  1101.                 string kindOflogin = neutralData["kindOfLogin"];
  1102.                 if (kindOflogin.Equals("instagram"))
  1103.                 {
  1104.                     loginAsInstagram();
  1105.                     Thread.Sleep(1500);
  1106.                 }
  1107.  
  1108.                 if (kindOflogin.Equals("facebook"))
  1109.                 {
  1110.                     loginAsFacebook();
  1111.                     Thread.Sleep(1000);
  1112.                 }
  1113.                 string json1 = File.ReadAllText(@"neutralData.json");
  1114.                 dynamic neutral = JsonConvert.DeserializeObject(json1);
  1115.                 loginSucces = neutral["loginSucces"];
  1116.  
  1117.                 Thread.Sleep(300);
  1118.             }
  1119.             currentLoginStatus(2);
  1120.             currentAction("Login Succes");
  1121.  
  1122.             string json2 = File.ReadAllText(@"neutralData.json");
  1123.             dynamic neutral1 = JsonConvert.DeserializeObject(json2);
  1124.             neutral1["loginStatus"] = true;
  1125.             string output2 = JsonConvert.SerializeObject(neutral1, Formatting.Indented);
  1126.             File.WriteAllText(@"neutralData.json", output2);
  1127.  
  1128.             Thread.Sleep(300);
  1129.  
  1130.  
  1131.  
  1132.         }
  1133.  
  1134.         static void startFastProgramm()
  1135.         {
  1136.             string json40 = File.ReadAllText(@"config/data.json");
  1137.             dynamic data = JsonConvert.DeserializeObject(json40);
  1138.             IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
  1139.             int linkNumber = 1;
  1140.             int currentLike = 0;
  1141.             int currentFollow = 0;
  1142.             int currentComment = 0;
  1143.             string currentFollowId = data["currentFollowId"];
  1144.             int currentIdNumberFollow = Int32.Parse(currentFollowId);
  1145.             string currentLikeId = data["currentLikeId"];
  1146.             int currentIdNumberLike = Int32.Parse(currentLikeId);
  1147.             string currentCommId = data["currentCommId"];
  1148.             int currentIdNumberComm = Int32.Parse(currentCommId);
  1149.             int commError = 0;
  1150.  
  1151.             string json2 = File.ReadAllText(@"config/data.json");
  1152.             dynamic jsonObj2 = JsonConvert.DeserializeObject(json2);
  1153.             jsonObj2["commError"] = commError.ToString();
  1154.             string output2 = JsonConvert.SerializeObject(jsonObj2, Formatting.Indented);
  1155.             File.WriteAllText(@"config/data.json", output2);
  1156.             string tag = data["tag"];
  1157.             if (tag.Length > 20)
  1158.             {
  1159.                 driver.Navigate().GoToUrl(tag);
  1160.             }
  1161.             else
  1162.             {
  1163.                 driver.Navigate().GoToUrl("https://www.instagram.com/explore/tags/" + tag);
  1164.             }
  1165.             Thread.Sleep(2000);
  1166.             js.ExecuteScript("window.scrollTo(0, 500)");
  1167.             Thread.Sleep(1000);
  1168.             int likeBefore = dayLike();
  1169.             int commBefore = dayComm();
  1170.  
  1171.             hashatagError();
  1172.  
  1173.             string jsonUserName = File.ReadAllText(@"neutralData.json");
  1174.             dynamic neutral = JsonConvert.DeserializeObject(jsonUserName);
  1175.             string userNick = neutral["instagramUserName"];
  1176.  
  1177.             string clickFirstPost = path["clickFirstPost"];
  1178.             clickElementByXpath(clickFirstPost);
  1179.             string postNumber = data["postNumber"];
  1180.             currentAction("Working");
  1181.             for (int i = 1; i <= Int32.Parse(postNumber);)
  1182.             {
  1183.                 // exit programm
  1184.                 bool statusProgramm = programmStatus();
  1185.                 if (statusProgramm == true)
  1186.                     break;
  1187.  
  1188.                 if (currentIdNumberFollow == 11)
  1189.                 {
  1190.                     currentIdNumberFollow = 1;
  1191.                 }
  1192.                 if (currentIdNumberLike == 11)
  1193.                 {
  1194.                     currentIdNumberLike = 1;
  1195.                 }
  1196.                 if (currentIdNumberComm == 11)
  1197.                 {
  1198.                     currentIdNumberComm = 1;
  1199.                 }
  1200.              
  1201.  
  1202.                 string likePost = path["likePost"];
  1203.                 string loadPost = checkElementByXpath3(likePost);
  1204.  
  1205.                 string downloadPostName = path["downloadPostName"];
  1206.                 string userName = getAttributeByXpath(downloadPostName, "innerHTML").Trim();
  1207.  
  1208.                 if (loadPost.Equals("false") && userName != userNick)
  1209.                 {
  1210.                     string checkLikeStatus = path["checkLikeStatus"];
  1211.                     string likeStatus = getAttributeByCssSelector(checkLikeStatus, "fill");
  1212.  
  1213.                     //like
  1214.                     string likeFillWithoutLike = path["likeFillWithoutLike"];
  1215.                     if (likeStatus.Equals(likeFillWithoutLike))
  1216.                     {
  1217.                         clickElementByXpath(likePost);
  1218.  
  1219.                         string checkPostError = path["checkPostError"];
  1220.                         string errorCheck = checkElementByXpath2(checkPostError);
  1221.                         saveLikeStats(currentIdNumberLike);
  1222.                         currentIdNumberLike++;
  1223.                         Thread.Sleep(600);
  1224.                         useRandomTimeFast();
  1225.  
  1226.                         if (errorCheck.Equals("true"))
  1227.                         {   //follow
  1228.                             string follow = data["follow"];
  1229.                             if (follow.Equals("yes"))
  1230.                             {
  1231.                                 //co który post ma dac followa
  1232.                                 string postToFollow = data["postToFollow"];
  1233.                                 if (i % Int32.Parse(postToFollow) == 0)
  1234.                                 {
  1235.                                     // follow limit
  1236.                                     if (currentFollow <= 60)
  1237.                                     {
  1238.                                         string checkFollowStatus = path["checkFollowStatus"];
  1239.                                         string followStatus = getAttributeByXpath(checkFollowStatus, "class");
  1240.  
  1241.                                         //follow status
  1242.                                         string followClassWithoutFollow = path["followClassWithoutFollow"];
  1243.                                         if (followStatus.Equals(followClassWithoutFollow))
  1244.                                         {
  1245.                                             string followAccount = path["followAccount"];
  1246.                                             clickElementByXpath(followAccount);
  1247.                                             saveFollowStats(currentIdNumberFollow);
  1248.                                             currentFollow++;
  1249.                                             currentIdNumberFollow++;
  1250.                                             Thread.Sleep(500);
  1251.                                             useRandomTimeFast();
  1252.                                         }
  1253.                                     }
  1254.                                 }
  1255.  
  1256.                             }
  1257.  
  1258.                             //comm
  1259.                             string comment = data["comment"];
  1260.                             if (comment.Equals("yes"))
  1261.                             {
  1262.                                 if (commError <= 5)
  1263.                                 {
  1264.                                     //limit komantarzy
  1265.                                     if (currentComment <= 50)
  1266.                                     {
  1267.                                         // co który post ma dostac komma
  1268.                                         string postToComment = data["postToComment"];
  1269.                                         if (i % Int32.Parse(postToComment) == 0)
  1270.                                         {
  1271.                                             // czy nie ma blokady komm
  1272.                                             string checkCommentStatus = path["checkCommentStatus"];
  1273.                                             string commentStatus = checkElementByXpath(checkCommentStatus);
  1274.                                             if (commentStatus.Equals("true"))
  1275.                                             {
  1276.                                                 string textMessage = randomComm();
  1277.                                                 string writeComment = path["writeComment"];
  1278.                                                 clickElementByXpath(writeComment);
  1279.  
  1280.                                                 Thread.Sleep(300);
  1281.  
  1282.                                                 string writeCommentVisible = path["writeCommentVisible"];
  1283.                                                 sendKeysByXpath(writeCommentVisible, textMessage);
  1284.  
  1285.                                                 Thread.Sleep(500);
  1286.  
  1287.                                                 string sendComment = path["sendComment"];
  1288.                                                 clickElementByXpath(sendComment);
  1289.  
  1290.                                                 Thread.Sleep(400);
  1291.  
  1292.                                                 string commentAfterSendError = path["commentAfterSendError"];
  1293.                                                 string checkErrorComm = checkElementByXpath2(commentAfterSendError);
  1294.                                                 // "spróbuj ponownie w komm"
  1295.                                                 if (checkErrorComm.Equals("true"))
  1296.                                                 {
  1297.                                                     saveCommStats(currentIdNumberComm);
  1298.                                                     currentIdNumberComm++;
  1299.                                                     currentComment++;
  1300.                                                     useRandomTimeFast();
  1301.                                                 }
  1302.                                                 else
  1303.                                                 {
  1304.                                                     Console.WriteLine("Błąd w komantarzu");
  1305.                                                     commError++;
  1306.                                                 }
  1307.                                             }
  1308.                                         }
  1309.                                     }
  1310.                                 }
  1311.                             }
  1312.                             i++;
  1313.                             currentLike++;
  1314.                         }
  1315.                         else
  1316.                         {
  1317.                             Console.WriteLine("Napotkano ERROR, koniec programu");
  1318.                             string json4 = File.ReadAllText(@"config/data.json");
  1319.                             dynamic jsonObj4 = JsonConvert.DeserializeObject(json4);
  1320.                             jsonObj4["igError"] = "True";
  1321.                             string output4 = JsonConvert.SerializeObject(jsonObj4, Formatting.Indented);
  1322.                             File.WriteAllText(@"config/data.json", output4);
  1323.                             Thread.Sleep(5000);
  1324.                             driver.Close();
  1325.                             driver.Quit();
  1326.                             Environment.Exit(0);
  1327.                         }
  1328.  
  1329.                         //save stats to data.json
  1330.                         string json = File.ReadAllText(@"config/data.json");
  1331.                         dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1332.                         jsonObj["currentLike"] = currentLike.ToString();
  1333.                         jsonObj["currentFollow"] = currentFollow.ToString();
  1334.                         jsonObj["currentComment"] = currentComment.ToString();
  1335.                         string totalLike = data["totalLike"];
  1336.                         jsonObj["totalLike"] = (currentLike + Int32.Parse(totalLike)).ToString();
  1337.                         string totalFollow = data["totalFollow"];
  1338.                         jsonObj["totalFollow"] = (currentFollow + Int32.Parse(totalFollow)).ToString();
  1339.                         string totalComment = data["totalComment"];
  1340.                         jsonObj["totalComment"] = (currentComment + Int32.Parse(totalComment)).ToString();
  1341.                         jsonObj["currentFollowId"] = currentIdNumberFollow.ToString();
  1342.                         jsonObj["currentLikeId"] = currentIdNumberLike.ToString();
  1343.                         jsonObj["currentCommId"] = currentIdNumberComm.ToString();
  1344.                         jsonObj["commError"] = commError.ToString();
  1345.                         string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1346.                         File.WriteAllText(@"config/data.json", output);
  1347.  
  1348.                         //save all likes in day (number)
  1349.                         string json1 = File.ReadAllText(@"config/likeDay.json");
  1350.                         dynamic jsonObj1 = JsonConvert.DeserializeObject(json1);
  1351.                         string date = DateTime.Now.ToString("dd.MM.yyy");
  1352.                         jsonObj1[date] = (currentLike + likeBefore).ToString();
  1353.                         string output1 = JsonConvert.SerializeObject(jsonObj1, Formatting.Indented);
  1354.                         File.WriteAllText(@"config/likeDay.json", output1);
  1355.  
  1356.  
  1357.                         //save all comm in day (number)
  1358.                         string json5 = File.ReadAllText(@"co nfig/commDay.json");
  1359.                         dynamic jsonObj5 = JsonConvert.DeserializeObject(json5);
  1360.                         jsonObj5[date] = (currentComment + commBefore).ToString();
  1361.                         string output5 = JsonConvert.SerializeObject(jsonObj5, Formatting.Indented);
  1362.                         File.WriteAllText(@"config/commDay.json", output5);
  1363.  
  1364.                         //save profile link
  1365.                         string downloadPostLink = path["downloadPostLink"];
  1366.                         string profileLink = getAttributeByCssSelector(downloadPostLink, "href");
  1367.  
  1368.                         bool linkBefore = checkLink(profileLink);
  1369.                         if (linkBefore == false)
  1370.                         {
  1371.                             string json3 = File.ReadAllText(@"config/linkToLike.json");
  1372.                             dynamic jsonObj3 = JsonConvert.DeserializeObject(json3);
  1373.                             jsonObj3["Link_id" + linkNumber] = profileLink;
  1374.                             string output3 = JsonConvert.SerializeObject(jsonObj3, Formatting.Indented);
  1375.                             File.WriteAllText(@"config/linkToLike.json", output3);
  1376.                             linkNumber++;
  1377.                         }
  1378.  
  1379.  
  1380.                         //next post
  1381.                         string nextPost = path["nextPost"];
  1382.                         clickElementByXpath(nextPost);
  1383.                         Thread.Sleep(500);
  1384.  
  1385.                     }
  1386.                     else
  1387.                     {
  1388.                         //next post
  1389.                         string nextPost = path["nextPost"];
  1390.                         clickElementByXpath(nextPost);
  1391.                         Thread.Sleep(600);
  1392.                     }
  1393.                 }
  1394.                 else
  1395.                 {
  1396.                     //next post
  1397.                     string nextPost = path["nextPost"];
  1398.                     clickElementByXpath(nextPost);
  1399.                     Thread.Sleep(600);
  1400.                 }
  1401.             }
  1402.         }
  1403.  
  1404.         static bool checkLink(string link)
  1405.         {
  1406.             string strResult = File.ReadAllText(@"config/linkTolike.json");
  1407.  
  1408.             var dictionary = JsonConvert.DeserializeObject<IDictionary>(strResult);
  1409.  
  1410.             foreach (DictionaryEntry elem in dictionary)
  1411.             {
  1412.  
  1413.                 if (elem.Value.ToString().Equals(link))
  1414.                 {
  1415.                     return true;
  1416.                 }
  1417.             }
  1418.             return false;
  1419.  
  1420.         }
  1421.  
  1422.         static void startSafeProgramm()
  1423.         {
  1424.             string json20 = File.ReadAllText(@"config/data.json");
  1425.             dynamic data = JsonConvert.DeserializeObject(json20);
  1426.             IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
  1427.             int linkNumber = 1;
  1428.             int currentLike = 0;
  1429.             int currentFollow = 0;
  1430.             int currentComment = 0;
  1431.             string currentFollowId = data["currentFollowId"];
  1432.             int currentIdNumberFollow = Int32.Parse(currentFollowId);
  1433.             string currentLikeId = data["currentLikeId"];
  1434.             int currentIdNumberLike = Int32.Parse(currentLikeId);
  1435.             string currentCommId = data["currentCommId"];
  1436.             int currentIdNumberComm = Int32.Parse(currentCommId);
  1437.             int commError = 0;
  1438.  
  1439.             string json2 = File.ReadAllText(@"config/data.json");
  1440.             dynamic jsonObj2 = JsonConvert.DeserializeObject(json2);
  1441.             jsonObj2["commError"] = commError.ToString();
  1442.             string output2 = JsonConvert.SerializeObject(jsonObj2, Formatting.Indented);
  1443.             File.WriteAllText(@"config/data.json", output2);
  1444.             string tag = data["tag"];
  1445.             if (tag.Length > 20)
  1446.             {
  1447.                 driver.Navigate().GoToUrl(tag);
  1448.             }
  1449.             else
  1450.             {
  1451.                 driver.Navigate().GoToUrl("https://www.instagram.com/explore/tags/" + tag);
  1452.             }
  1453.  
  1454.  
  1455.             Thread.Sleep(2000);
  1456.             js.ExecuteScript("window.scrollTo(0, 500)");
  1457.             Thread.Sleep(1000);
  1458.  
  1459.             int likeBefore = dayLike();
  1460.             int commBefore = dayComm();
  1461.  
  1462.             hashatagError();
  1463.  
  1464.             string clickFirstPost = path["clickFirstPost"];
  1465.             clickElementByXpath(clickFirstPost);
  1466.             string postNumber = data["postNumber"];
  1467.             currentAction("Working - Safe Mode");
  1468.             for (int i = 1; i <= Int32.Parse(postNumber);)
  1469.             {
  1470.                 // exit programm
  1471.                 bool statusProgramm = programmStatus();
  1472.                 if (statusProgramm == true)
  1473.                     break;
  1474.  
  1475.                 if (currentIdNumberFollow == 11)
  1476.                 {
  1477.                     currentIdNumberFollow = 1;
  1478.                 }
  1479.                 if (currentIdNumberLike == 11)
  1480.                 {
  1481.                     currentIdNumberLike = 1;
  1482.                 }
  1483.                 if (currentIdNumberComm == 11)
  1484.                 {
  1485.                     currentIdNumberComm = 1;
  1486.                 }
  1487.                 if (currentLike + likeBefore >= 1500)
  1488.                 {
  1489.                     string json4 = File.ReadAllText(@"config/data.json");
  1490.                     dynamic jsonObj4 = JsonConvert.DeserializeObject(json4);
  1491.                     jsonObj4["igError"] = "True";
  1492.                     string output4 = JsonConvert.SerializeObject(jsonObj4, Formatting.Indented);
  1493.                     File.WriteAllText(@"config/data.json", output4);
  1494.                     Thread.Sleep(5000);
  1495.                     driver.Close();
  1496.                     driver.Quit();
  1497.                     Environment.Exit(0);
  1498.                 }
  1499.  
  1500.                 string likePost = path["likePost"];
  1501.                 string loadPost = checkElementByXpath3(likePost);
  1502.                 if (loadPost.Equals("false"))
  1503.                 {
  1504.                     string checkLikeStatus = path["checkLikeStatus"];
  1505.                     string likeStatus = getAttributeByCssSelector(checkLikeStatus, "fill");
  1506.  
  1507.                     //like
  1508.                     string likeFillWithoutLike = path["likeFillWithoutLike"];
  1509.                     if (likeStatus.Equals(likeFillWithoutLike))
  1510.                     {
  1511.                         clickElementByXpath(likePost);
  1512.  
  1513.                         string checkPostError = path["checkPostError"];
  1514.                         string errorCheck = checkElementByXpath2(checkPostError);
  1515.                         saveLikeStats(currentIdNumberLike);
  1516.                         currentIdNumberLike++;
  1517.                         Thread.Sleep(600);
  1518.                         useRandomTimeSafe();
  1519.  
  1520.                         if (errorCheck.Equals("true"))
  1521.                         {   //follow
  1522.                             string follow = data["follow"];
  1523.                             if (follow.Equals("yes"))
  1524.                             {
  1525.                                 //co który post ma dac followa
  1526.                                 string postToFollow = data["postToFollow"];
  1527.                                 if (i % Int32.Parse(postToFollow) == 0)
  1528.                                 {
  1529.                                     // follow limit
  1530.                                     if (currentFollow <= 60)
  1531.                                     {
  1532.                                         string checkFollowStatus = path["checkFollowStatus"];
  1533.                                         string followStatus = getAttributeByXpath(checkFollowStatus, "class");
  1534.  
  1535.                                         //follow status
  1536.                                         string followClassWithoutFollow = path["followClassWithoutFollow"];
  1537.                                         if (followStatus.Equals(followClassWithoutFollow))
  1538.                                         {
  1539.                                             string followAccount = path["followAccount"];
  1540.                                             clickElementByXpath(followAccount);
  1541.  
  1542.                                             saveFollowStats(currentIdNumberFollow);
  1543.                                             currentFollow++;
  1544.                                             currentIdNumberFollow++;
  1545.                                             Thread.Sleep(500);
  1546.                                             useRandomTimeSafe();
  1547.                                         }
  1548.                                     }
  1549.                                 }
  1550.  
  1551.                             }
  1552.  
  1553.                             //comm
  1554.                             string comment = data["comment"];
  1555.                             if (comment.Equals("yes"))
  1556.                             {
  1557.                                 if (commError <= 5)
  1558.                                 {
  1559.                                     //limit komantarzy
  1560.                                     if (currentComment <= 50)
  1561.                                     {
  1562.                                         // co który post ma dostac komma
  1563.                                         string postToComment = data["postToComment"];
  1564.                                         if (i % Int32.Parse(postToComment) == 0)
  1565.                                         {
  1566.                                             // czy nie ma blokady komm
  1567.                                             string checkCommentStatus = path["checkCommentStatus"];
  1568.                                             string commentStatus = checkElementByXpath(checkCommentStatus);
  1569.                                             if (commentStatus.Equals("true"))
  1570.                                             {
  1571.                                                 string textMessage = randomComm();
  1572.  
  1573.                                                 string writeComment = path["writeComment"];
  1574.                                                 clickElementByXpath(writeComment);
  1575.  
  1576.                                                 Thread.Sleep(300);
  1577.  
  1578.                                                 string writeCommentVisible = path["writeCommentVisible"];
  1579.                                                 sendKeysByXpath(writeCommentVisible, textMessage);
  1580.  
  1581.                                                 Thread.Sleep(500);
  1582.  
  1583.                                                 string sendComment = path["sendComment"];
  1584.                                                 clickElementByXpath(sendComment);
  1585.  
  1586.                                                 Thread.Sleep(400);
  1587.  
  1588.                                                 string commentAfterSendError = path["commentAfterSendError"];
  1589.                                                 string checkErrorComm = checkElementByXpath2(commentAfterSendError);
  1590.                                                 // "spróbuj ponownie w komm"
  1591.                                                 if (checkErrorComm.Equals("true"))
  1592.                                                 {
  1593.                                                     saveCommStats(currentIdNumberComm);
  1594.                                                     currentIdNumberComm++;
  1595.                                                     currentComment++;
  1596.                                                     useRandomTimeSafe();
  1597.                                                 }
  1598.                                                 else
  1599.                                                 {
  1600.                                                     Console.WriteLine("Błąd w komantarzu");
  1601.                                                     commError++;
  1602.                                                 }
  1603.                                             }
  1604.                                         }
  1605.                                     }
  1606.                                 }
  1607.                             }
  1608.                             i++;
  1609.                             currentLike++;
  1610.                         }
  1611.                         else
  1612.                         {
  1613.                             Console.WriteLine("Napotkano ERROR, koniec programu");
  1614.                             string json4 = File.ReadAllText(@"config/data.json");
  1615.                             dynamic jsonObj4 = JsonConvert.DeserializeObject(json4);
  1616.                             jsonObj4["igError"] = "True";
  1617.                             string output4 = JsonConvert.SerializeObject(jsonObj4, Formatting.Indented);
  1618.                             File.WriteAllText(@"config/data.json", output4);
  1619.                             Thread.Sleep(5000);
  1620.                             driver.Close();
  1621.                             driver.Quit();
  1622.                             Environment.Exit(0);
  1623.                         }
  1624.  
  1625.                         //save stats to data.json
  1626.                         string json = File.ReadAllText(@"config/data.json");
  1627.                         dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1628.                         jsonObj["currentLike"] = currentLike.ToString();
  1629.                         jsonObj["currentFollow"] = currentFollow.ToString();
  1630.                         jsonObj["currentComment"] = currentComment.ToString();
  1631.                         string totalLike = data["totalLike"];
  1632.                         jsonObj["totalLike"] = (currentLike + Int32.Parse(totalLike)).ToString();
  1633.                         string totalFollow = data["totalFollow"];
  1634.                         jsonObj["totalFollow"] = (currentFollow + Int32.Parse(totalFollow)).ToString();
  1635.                         string totalComment = data["totalComment"];
  1636.                         jsonObj["totalComment"] = (currentComment + Int32.Parse(totalComment)).ToString();
  1637.                         jsonObj["currentFollowId"] = currentIdNumberFollow.ToString();
  1638.                         jsonObj["currentLikeId"] = currentIdNumberLike.ToString();
  1639.                         jsonObj["currentCommId"] = currentIdNumberComm.ToString();
  1640.                         jsonObj["commError"] = commError.ToString();
  1641.                         string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1642.                         File.WriteAllText(@"config/data.json", output);
  1643.  
  1644.                         //save all likes in day (number)
  1645.                         string json1 = File.ReadAllText(@"config/likeDay.json");
  1646.                         dynamic jsonObj1 = JsonConvert.DeserializeObject(json1);
  1647.                         string date = DateTime.Now.ToString("dd.MM.yyy");
  1648.                         jsonObj1[date] = (currentLike + likeBefore).ToString();
  1649.                         string output1 = JsonConvert.SerializeObject(jsonObj1, Formatting.Indented);
  1650.                         File.WriteAllText(@"config/likeDay.json", output1);
  1651.  
  1652.  
  1653.                         //save all comm in day (number)
  1654.                         string json5 = File.ReadAllText(@"config/commDay.json");
  1655.                         dynamic jsonObj5 = JsonConvert.DeserializeObject(json5);
  1656.                         jsonObj5[date] = (currentComment + commBefore).ToString();
  1657.                         string output5 = JsonConvert.SerializeObject(jsonObj5, Formatting.Indented);
  1658.                         File.WriteAllText(@"config/commDay.json", output5);
  1659.  
  1660.                         //save profile link
  1661.                         string downloadPostLink = path["downloadPostLink"];
  1662.                         string profileLink = getAttributeByCssSelector(downloadPostLink, "href");
  1663.  
  1664.                         bool linkBefore = checkLink(profileLink);
  1665.                         if (linkBefore == false)
  1666.                         {
  1667.                             string json3 = File.ReadAllText(@"config/linkToLike.json");
  1668.                             dynamic jsonObj3 = JsonConvert.DeserializeObject(json3);
  1669.                             jsonObj3["Link_id" + linkNumber] = profileLink;
  1670.                             string output3 = JsonConvert.SerializeObject(jsonObj3, Formatting.Indented);
  1671.                             File.WriteAllText(@"config/linkToLike.json", output3);
  1672.                             linkNumber++;
  1673.                         }
  1674.  
  1675.                         if (i % 20 == 0)
  1676.                         {
  1677.                             Thread.Sleep(rnd.Next(300000, 350000));
  1678.                         }
  1679.  
  1680.                         //next post
  1681.                         string nextPost = path["nextPost"];
  1682.                         clickElementByXpath(nextPost);
  1683.                         Thread.Sleep(500);
  1684.  
  1685.                     }
  1686.                     else
  1687.                     {
  1688.                         //next post
  1689.                         string nextPost = path["nextPost"];
  1690.                         clickElementByXpath(nextPost);
  1691.                         Thread.Sleep(600);
  1692.                     }
  1693.                 }
  1694.                 else
  1695.                 {
  1696.                     //next post
  1697.                     string nextPost = path["nextPost"];
  1698.                     clickElementByXpath(nextPost);
  1699.                     Thread.Sleep(600);
  1700.                 }
  1701.             }
  1702.         }
  1703.  
  1704.         static bool programmStatus()
  1705.         {
  1706.             string json100 = File.ReadAllText(@"neutralData.json");
  1707.             dynamic neutral = JsonConvert.DeserializeObject(json100);
  1708.             bool x = neutral["exitTheProgram"];
  1709.             return x;
  1710.         }
  1711.  
  1712.        
  1713.  
  1714.         static void numberOfAllFollowesInAccount()
  1715.         {
  1716.             string json2 = File.ReadAllText(@"config/data.json");
  1717.             dynamic data = JsonConvert.DeserializeObject(json2);
  1718.             string checkFollowStatus = data["firstFollowCheck"];
  1719.  
  1720.             string json3 = File.ReadAllText(@"neutralData.json");
  1721.             dynamic neutral = JsonConvert.DeserializeObject(json3);
  1722.             string url = neutral["instagramUserName"];
  1723.             driver.Navigate().GoToUrl("https://www.instagram.com/" + url);
  1724.  
  1725.             if (checkFollowStatus.Equals("false"))
  1726.             {
  1727.                 Thread.Sleep(1000);
  1728.  
  1729.                 string getNumberOfFollowesInAccount = path["getNumberOfFollowesInAccount"];
  1730.                 string numberOfAllFollows = getAttributeByCssSelector(getNumberOfFollowesInAccount, "title");
  1731.  
  1732.                 string json = File.ReadAllText(@"config/data.json");
  1733.                 dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1734.                 jsonObj["allFollowesBefore"] = numberOfAllFollows.ToString();
  1735.                 jsonObj["firstFollowCheck"] = "true";
  1736.                 string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1737.                 File.WriteAllText(@"config/data.json", output);
  1738.             }
  1739.  
  1740.  
  1741.         }
  1742.  
  1743.         static void numberOfAllNewFollowesInAccount()
  1744.         {
  1745.             string json4 = File.ReadAllText(@"neutralData.json");
  1746.             dynamic neutral = JsonConvert.DeserializeObject(json4);
  1747.             string url = neutral["instagramUserName"];
  1748.             driver.Navigate().GoToUrl("https://www.instagram.com/" + url);
  1749.             Thread.Sleep(3000);
  1750.  
  1751.             string getNumberOfFollowesInAccount = path["getNumberOfFollowesInAccount"];
  1752.             string numberOfAllFollows = getAttributeByCssSelector(getNumberOfFollowesInAccount, "title");
  1753.  
  1754.             Thread.Sleep(1000);
  1755.  
  1756.  
  1757.             string json = File.ReadAllText(@"config/data.json");
  1758.             dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1759.             jsonObj["allFollowesAfter"] = numberOfAllFollows.ToString();
  1760.             string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1761.             File.WriteAllText(@"config/data.json", output);
  1762.  
  1763.             Thread.Sleep(300);
  1764.  
  1765.             string date = DateTime.Now.ToString("dd.MM.yyy");
  1766.             string json3 = File.ReadAllText(@"config/followDay.json");
  1767.             dynamic jsonObj3 = JsonConvert.DeserializeObject(json3);
  1768.             string currentSaveDate = jsonObj3[date];
  1769.             Console.WriteLine(currentSaveDate + "to");
  1770.             if (currentSaveDate == null)
  1771.             {
  1772.                 jsonObj3[date] = numberOfAllFollows.ToString();
  1773.  
  1774.                 string output3 = JsonConvert.SerializeObject(jsonObj3, Formatting.Indented);
  1775.                 File.WriteAllText(@"config/followDay.json", output3);
  1776.             }
  1777.  
  1778.  
  1779.             string json2 = File.ReadAllText(@"config/data.json");
  1780.             dynamic jsonObj2 = JsonConvert.DeserializeObject(json2);
  1781.             string followersToday = jsonObj3[date];
  1782.             int moreFollowes = Int32.Parse(numberOfAllFollows) - Int32.Parse(followersToday);
  1783.             jsonObj2["newFollowersNumber"] = moreFollowes.ToString();
  1784.             string output2 = JsonConvert.SerializeObject(jsonObj2, Formatting.Indented);
  1785.             File.WriteAllText(@"config/data.json", output2);
  1786.  
  1787.  
  1788.  
  1789.         }
  1790.  
  1791.         static bool codeCheck()
  1792.         {
  1793.             string json = File.ReadAllText(@"neutralData.json");
  1794.             dynamic data = JsonConvert.DeserializeObject(json);
  1795.             int correctCode = (DateTime.Now.DayOfYear * 2137 * DateTime.DaysInMonth(2001, 2));
  1796.  
  1797.             string code = data["code"];
  1798.             int jsonCode = Int32.Parse(code);
  1799.             Console.WriteLine(correctCode);
  1800.             if (jsonCode == correctCode)
  1801.             {
  1802.                 return true;
  1803.             }
  1804.             else
  1805.             {
  1806.                 return false;
  1807.             }
  1808.         }
  1809.  
  1810.         public static string Decrypt(string cipherText)
  1811.         {
  1812.             string EncryptionKey = "Ex*igdqx49fX7ilPqIdYF!gZ";
  1813.             cipherText = cipherText.Replace(" ", "+");
  1814.             byte[] cipherBytes = Convert.FromBase64String(cipherText);
  1815.             using (Aes encryptor = Aes.Create())
  1816.             {
  1817.                 Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
  1818.                 encryptor.Key = pdb.GetBytes(32);
  1819.                 encryptor.IV = pdb.GetBytes(16);
  1820.                 using (MemoryStream ms = new MemoryStream())
  1821.                 {
  1822.                     using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
  1823.                     {
  1824.                         cs.Write(cipherBytes, 0, cipherBytes.Length);
  1825.                         cs.Close();
  1826.                     }
  1827.                     cipherText = Encoding.Unicode.GetString(ms.ToArray());
  1828.                 }
  1829.             }
  1830.             return cipherText;
  1831.         }
  1832.  
  1833.         static void numberOfAllPostInAccount()
  1834.         {
  1835.  
  1836.             string getNumberOfPostInAccount = path["getNumberOfPostInAccount"];
  1837.             string postNumber = getAttributeByXpath(getNumberOfPostInAccount, "innerHTML");
  1838.             string json = File.ReadAllText(@"config/data.json");
  1839.             dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1840.             jsonObj["totalPostInAccount"] = postNumber.ToString();
  1841.  
  1842.             string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1843.             File.WriteAllText(@"config/data.json", output);
  1844.         }
  1845.  
  1846.         static void getPostAndFollowesNumber()
  1847.         {
  1848.  
  1849.             currentAction("Working - Get Stats");
  1850.             numberOfAllFollowesInAccount();
  1851.             numberOfAllNewFollowesInAccount();
  1852.             //numberOfAllPostInAccount();
  1853.             downloadUserPhoto();
  1854.         }
  1855.  
  1856.         static void getUserName()
  1857.         {
  1858.             currentLoginStatus(3);
  1859.             string quitInstagramNotifi = path["quitInstagramNotifi"];
  1860.             string notifyStatus = checkElementByXpath2(quitInstagramNotifi);
  1861.             if (notifyStatus.Equals("false"))
  1862.             {
  1863.                 clickElementByXpath(quitInstagramNotifi);
  1864.             }
  1865.  
  1866.  
  1867.             string profileMenuBar = path["profileMenuBar"];
  1868.             clickElementByXpath(profileMenuBar);
  1869.  
  1870.             Thread.Sleep(1000);
  1871.  
  1872.             string goToProfile = path["goToProfile"];
  1873.             clickElementByXpath(goToProfile);
  1874.  
  1875.             //save user name
  1876.             string getUserName = path["getUserName"];
  1877.             string accountName = getAttributeByXpath(getUserName, "innerHTML");
  1878.  
  1879.             string json20 = File.ReadAllText(@"neutralData.json");
  1880.             dynamic jsonObj20 = JsonConvert.DeserializeObject(json20);
  1881.             jsonObj20["instagramUserName"] = accountName;
  1882.             string output20 = JsonConvert.SerializeObject(jsonObj20, Formatting.Indented);
  1883.             File.WriteAllText(@"neutralData.json", output20);
  1884.  
  1885.             Thread.Sleep(100);
  1886.             currentLoginStatus(4);
  1887.         }
  1888.  
  1889.         static void downloadUserPhoto()
  1890.         {
  1891.             WebClient client = new WebClient();
  1892.             try
  1893.             {
  1894.                 Thread.Sleep(1000);
  1895.  
  1896.                 string downloadUserPhotoInAccount = path["downloadUserPhotoInAccount"];
  1897.                 string url = driver.FindElement(By.XPath(downloadUserPhotoInAccount)).GetAttribute("src");
  1898.                 client.DownloadFile(new Uri(url), @"config/userPhoto.jpeg");
  1899.             }
  1900.             catch
  1901.             {
  1902.                 Thread.Sleep(100);
  1903.             }
  1904.             try
  1905.             {
  1906.                 Thread.Sleep(1000);
  1907.  
  1908.                 string secondDownloadUserPhoto = path["secondDownloadUserPhoto"];
  1909.                 string url = driver.FindElement(By.XPath(secondDownloadUserPhoto)).GetAttribute("src");
  1910.                 client.DownloadFile(new Uri(url), @"config/userPhoto.jpeg");
  1911.             }
  1912.             catch
  1913.             {
  1914.                 Thread.Sleep(100);
  1915.             }
  1916.  
  1917.  
  1918.  
  1919.         }
  1920.  
  1921.         static void saveFollowStats(int followIdNumber)
  1922.         {
  1923.             string json2 = File.ReadAllText(@"config/data.json");
  1924.             dynamic data = JsonConvert.DeserializeObject(json2);
  1925.             WebClient client = new WebClient();
  1926.  
  1927.             string downloadPostPhoto = path["downloadPostPhoto"];
  1928.             string photoUrl = getAttributeByCssSelector2(downloadPostPhoto, "src");
  1929.  
  1930.             string downloadPostName = path["downloadPostName"];
  1931.             string userName = getAttributeByXpath(downloadPostName, "innerHTML");
  1932.  
  1933.             if (photoUrl.Equals("false") || data["savePhoto"].Equals("false"))
  1934.             {
  1935.                 System.IO.File.Copy("none.jpg", @"photoFollow/name_id" + followIdNumber + ".jpeg", true);
  1936.             }
  1937.             else
  1938.             {
  1939.                 client.DownloadFile(new Uri(photoUrl), @"photoFollow/name_id" + followIdNumber + ".jpeg");
  1940.             }
  1941.  
  1942.             string json = File.ReadAllText(@"config/followNames.json");
  1943.             dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1944.             jsonObj["name_Id" + followIdNumber] = userName;
  1945.             string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1946.             File.WriteAllText(@"config/followNames.json", output);
  1947.  
  1948.         }
  1949.  
  1950.         static void saveLikeStats(int likeIdNumber)
  1951.         {
  1952.             string json2 = File.ReadAllText(@"config/data.json");
  1953.             dynamic data = JsonConvert.DeserializeObject(json2);
  1954.             WebClient client = new WebClient();
  1955.  
  1956.             string downloadPostPhoto = path["downloadPostPhoto"];
  1957.             string photoUrl = getAttributeByCssSelector2(downloadPostPhoto, "src");
  1958.  
  1959.             string downloadPostName = path["downloadPostName"];
  1960.             string userName = getAttributeByXpath(downloadPostName, "innerHTML");
  1961.  
  1962.  
  1963.             if (photoUrl.Equals("false") || data["savePhoto"].Equals("false"))
  1964.             {
  1965.                 System.IO.File.Copy("none.jpg", @"photoLike/name_id" + likeIdNumber + ".jpeg", true);
  1966.             }
  1967.             else
  1968.             {
  1969.                 client.DownloadFile(new Uri(photoUrl), @"photoLike/name_id" + likeIdNumber + ".jpeg");
  1970.             }
  1971.  
  1972.             string json = File.ReadAllText(@"config/likeNames.json");
  1973.             dynamic jsonObj = JsonConvert.DeserializeObject(json);
  1974.             jsonObj["name_Id" + likeIdNumber] = userName;
  1975.             string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  1976.             File.WriteAllText(@"config/likeNames.json", output);
  1977.         }
  1978.  
  1979.         static void saveCommStats(int likeIdNumber)
  1980.         {
  1981.             string json2 = File.ReadAllText(@"config/data.json");
  1982.             dynamic data = JsonConvert.DeserializeObject(json2);
  1983.             WebClient client = new WebClient();
  1984.  
  1985.  
  1986.             string downloadPostPhoto = path["downloadPostPhoto"];
  1987.             string photoUrl = getAttributeByCssSelector2(downloadPostPhoto, "src");
  1988.  
  1989.             string downloadPostName = path["downloadPostName"];
  1990.             string userName = getAttributeByXpath(downloadPostName, "innerHTML");
  1991.  
  1992.             if (photoUrl.Equals("false") || data["savePhoto"].Equals("false"))
  1993.             {
  1994.                 System.IO.File.Copy("none.jpg", @"photoComm/name_id" + likeIdNumber + ".jpeg", true);
  1995.             }
  1996.             else
  1997.             {
  1998.                 client.DownloadFile(new Uri(photoUrl), @"photoComm/name_id" + likeIdNumber + ".jpeg");
  1999.             }
  2000.  
  2001.  
  2002.             string json = File.ReadAllText(@"config/commNames.json");
  2003.             dynamic jsonObj = JsonConvert.DeserializeObject(json);
  2004.             jsonObj["name_Id" + likeIdNumber] = userName;
  2005.             string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  2006.             File.WriteAllText(@"config/commNames.json", output);
  2007.         }
  2008.  
  2009.         static void kindOfProgramm()
  2010.         {
  2011.             string json = File.ReadAllText(@"config/data.json");
  2012.             dynamic data = JsonConvert.DeserializeObject(json);
  2013.             string programType = data["kindOfProgramm"];
  2014.             if (programType.Equals("safe"))
  2015.             {
  2016.                 startSafeProgramm();
  2017.             }
  2018.             else if (programType.Equals("fast"))
  2019.             {
  2020.                 startFastProgramm();
  2021.             }
  2022.             else
  2023.             {
  2024.                 Console.WriteLine("Error Programm type");
  2025.             }
  2026.         }
  2027.  
  2028.         static void likePostFromLink()
  2029.         {
  2030.             string json2 = File.ReadAllText(@"config/data.json");
  2031.             dynamic data = JsonConvert.DeserializeObject(json2);
  2032.             int likeBefore = dayProfileLike();
  2033.             currentAction("Working - Like Posts In Accounts");
  2034.             string likePostFromLink = data["likePostFromLink"];
  2035.             if (likePostFromLink.Equals("true"))
  2036.             {
  2037.                 int currentLike = 0;
  2038.                 IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
  2039.                 string strResult = File.ReadAllText(@"config/linkTolike.json");
  2040.  
  2041.                 var dictionary = JsonConvert.DeserializeObject<IDictionary>(strResult);
  2042.  
  2043.                 foreach (DictionaryEntry elem in dictionary)
  2044.                 {
  2045.                     // exit programm
  2046.                     bool statusProgramm = programmStatus();
  2047.                     if (statusProgramm == true)
  2048.                         break;
  2049.  
  2050.                     string like = data["likeFromLinksNumber"];
  2051.                     if (currentLike <= Int32.Parse(like))
  2052.                     {
  2053.                         Thread.Sleep(1000);
  2054.                         Console.WriteLine(elem.Value);
  2055.                         driver.Navigate().GoToUrl(elem.Value.ToString());
  2056.                         Thread.Sleep(1000);
  2057.  
  2058.                         string noAccount = path["noAccount"];
  2059.                         int noAccount1 = driver.FindElements(By.ClassName(noAccount)).Count;
  2060.  
  2061.                         string clickFirstPostInAccount = path["clickFirstPostInAccount"];
  2062.                         int availabePost = driver.FindElements(By.ClassName(clickFirstPostInAccount)).Count;
  2063.                         if (noAccount1 == 0 && availabePost != 0)
  2064.                         {
  2065.                             Thread.Sleep(2000);
  2066.                             js.ExecuteScript("window.scrollTo(0, 400)");
  2067.                             Thread.Sleep(400);
  2068.  
  2069.  
  2070.                             clickElementByClassName(clickFirstPostInAccount);
  2071.                             int likeRandom = rnd.Next(3, 5);
  2072.  
  2073.                             for (int i = 1; i <= likeRandom;)
  2074.                             {
  2075.                                
  2076.                                 string checkPostError = path["checkPostError"];
  2077.                                 string errorCheck = checkElementByXpath2(checkPostError);
  2078.  
  2079.                                 string likePost = path["likePost"];
  2080.                                 string loadPost = checkElementByXpath3(likePost);
  2081.                                 if (errorCheck.Equals("true"))
  2082.                                 {
  2083.                                     if (loadPost.Equals("false"))
  2084.                                     {
  2085.                                         string nextPostInAccount = path["nextPostInAccount"];
  2086.                                         string nextPostStatus = checkElementByXpath2(nextPostInAccount);
  2087.                                         Console.WriteLine(nextPostStatus);
  2088.                                         if (nextPostStatus.Equals("false"))
  2089.                                         {
  2090.                                             string checkLikeStatus1 = path["checkLikeStatus"];
  2091.                                             string checkLikeStatus = getAttributeByCssSelector(checkLikeStatus1, "fill");
  2092.  
  2093.                                             string likeFillWithoutLike = path["likeFillWithoutLike"];
  2094.                                             if (checkLikeStatus.Equals(likeFillWithoutLike))
  2095.                                             {
  2096.                                                 i++;
  2097.                                                 currentLike++;
  2098.  
  2099.                                                 //like post
  2100.                                                 useRandomTimeFast();
  2101.  
  2102.  
  2103.                                                 clickElementByXpath(likePost);
  2104.  
  2105.                                                 //save like in day
  2106.                                                 string json5 = File.ReadAllText(@"config/profileLikeDay.json");
  2107.                                                 dynamic jsonObj5 = JsonConvert.DeserializeObject(json5);
  2108.                                                 string date = DateTime.Now.ToString("dd.MM.yyy");
  2109.                                                 jsonObj5[date] = (currentLike + likeBefore).ToString();
  2110.                                                 string output5 = JsonConvert.SerializeObject(jsonObj5, Formatting.Indented);
  2111.                                                 File.WriteAllText(@"config/profileLikeDay.json", output5);
  2112.  
  2113.                                                 //check error
  2114.  
  2115.                                                 string errorCheck1 = checkElementByXpath2(checkPostError);
  2116.                                                 if (errorCheck1.Equals("true"))
  2117.                                                 {
  2118.                                                     useRandomTimeFast();
  2119.                                                     //next post
  2120.  
  2121.                                                     clickElementByXpath(nextPostInAccount);
  2122.  
  2123.                                                     string json = File.ReadAllText(@"config/data.json");
  2124.                                                     dynamic jsonObj = JsonConvert.DeserializeObject(json);
  2125.                                                     jsonObj["likesInAccountFromLinks"] = currentLike.ToString();
  2126.                                                     string likes = data["totalLikeFromLinksNumber"];
  2127.                                                     jsonObj["totalLikeFromLinksNumber"] = (Int32.Parse(likes) + currentLike).ToString();
  2128.                                                     string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
  2129.                                                     File.WriteAllText(@"config/data.json", output);
  2130.                                                     Thread.Sleep(rnd.Next(400, 700));
  2131.                                                 }
  2132.                                                 else
  2133.                                                 {
  2134.                                                     Console.WriteLine("Napotkano ERROR, koniec programu");
  2135.                                                     string json4 = File.ReadAllText(@"config/data.json");
  2136.                                                     dynamic jsonObj4 = JsonConvert.DeserializeObject(json4);
  2137.                                                     jsonObj4["igError"] = "True";
  2138.                                                     string output4 = JsonConvert.SerializeObject(jsonObj4, Formatting.Indented);
  2139.                                                     File.WriteAllText(@"config/data.json", output4);
  2140.                                                     Thread.Sleep(5000);
  2141.                                                     Environment.Exit(0);
  2142.                                                 }
  2143.                                             }
  2144.                                             else
  2145.                                             {
  2146.                                                 // next post
  2147.                                                 clickElementByXpath(nextPostInAccount);
  2148.                                                 useRandomTimeFast();
  2149.                                             }
  2150.                                         }
  2151.                                         else
  2152.                                         {
  2153.                                             i = 7;
  2154.                                             Thread.Sleep(rnd.Next(250, 350));
  2155.                                         }
  2156.                                         ///html/body/div[4]/div[1]/div/div/a
  2157.                                         ///html/body/div[4]/div[1]/div/div/a[2]
  2158.  
  2159.                                     }
  2160.                                     else
  2161.                                     {
  2162.                                         string nextPostInAccount = path["nextPostInAccount"];
  2163.                                         string nextPostStatus = checkElementByXpath2(nextPostInAccount);
  2164.                                         Console.WriteLine(nextPostStatus);
  2165.                                         if (nextPostStatus.Equals("false"))
  2166.                                         {
  2167.                                             clickElementByXpath(nextPostInAccount);
  2168.                                             useRandomTimeFast();
  2169.                                         }
  2170.                                         else
  2171.                                         {
  2172.                                             i = 4;
  2173.                                             useRandomTimeFast();
  2174.                                         }
  2175.  
  2176.                                     }
  2177.  
  2178.                                 }
  2179.                                 else
  2180.                                 {
  2181.                                     Console.WriteLine("Napotkano ERROR, koniec programu");
  2182.                                     string json4 = File.ReadAllText(@"config/data.json");
  2183.                                     dynamic jsonObj4 = JsonConvert.DeserializeObject(json4);
  2184.                                     jsonObj4["igError"] = "True";
  2185.                                     string output4 = JsonConvert.SerializeObject(jsonObj4, Formatting.Indented);
  2186.                                     File.WriteAllText(@"config/data.json", output4);
  2187.                                     Thread.Sleep(5000);
  2188.                                     Environment.Exit(0);
  2189.                                 }
  2190.                             }
  2191.                         }
  2192.                     }
  2193.  
  2194.  
  2195.                 }
  2196.             }
  2197.         }
  2198.  
  2199.         static void accountAge()
  2200.         {
  2201.             Thread.Sleep(1000);
  2202.             driver.Navigate().GoToUrl("https://www.instagram.com/accounts/access_tool/?hl=pl");
  2203.             Thread.Sleep(1000);
  2204.             string accountDate = path["accountDate"];
  2205.             string dateWithHour = getAttributeByXpath(accountDate, "innerHTML").Trim();
  2206.             string date = string.Concat(dateWithHour.Reverse().Skip(6).Reverse());
  2207.             Console.WriteLine(date);
  2208.  
  2209.             DateTime time = DateTime.Parse(date);
  2210.             DateTime now = DateTime.Now;
  2211.             float day = (now - time).Days;
  2212.             Console.WriteLine(day);
  2213.             string json = File.ReadAllText(@"config/data.json");
  2214.             dynamic data = JsonConvert.DeserializeObject(json);
  2215.             string followNumberS = data["allFollowesAfter"];
  2216.             float followNumber = Convert.ToSingle(followNumberS);
  2217.             Console.WriteLine(followNumber);
  2218.             data["rate"] = followNumber / day;
  2219.             Console.WriteLine(followNumber / day);
  2220.             string output = JsonConvert.SerializeObject(data, Formatting.Indented);
  2221.             File.WriteAllText(@"config/data.json", output);
  2222.         }
  2223.  
  2224.        
  2225.     }
  2226. }
  2227.