コード例 #1
0
        static async Task Share(DealPublisher publisher, Option opt, string taskPath, string statusPath)
        {
            publisher.driver.Navigate().GoToUrl(@"https://www.smzdm.com/baoliao/?old");
            Thread.Sleep(5000);
            publisher.ReadInfo();
            if (publisher.baoLiaoLeft != 0)
            {
                DealFinder finder = new DealFinder(opt);
                while (publisher.baoLiaoLeft != 0)
                {
                    String content;
                    using (StreamReader reader = File.OpenText(taskPath))
                    {
                        content = await reader.ReadToEndAsync();
                    }
                    content = ProcessTask(content, opt, out Tuple <string, int> task);
                    await WriteFileAsync(taskPath, content);

                    Console.WriteLine("Write done.");
                    opt.Topic = task.Item1;
                    Console.WriteLine(opt.Topic);
                    Console.Title = opt.username + " " + task.Item1 + task.Item2 + " " + publisher.baoLiaoLeft;
                    var pageUrl = Helper.GetTopicUrl(opt.Topic, task.Item2.ToString());
                    if (pageUrl == null)
                    {
                        return;
                    }
                    var exceptionCount = 0;
                    while (exceptionCount < 5)
                    {
                        try
                        {
                            FindDealAndPublish(opt, pageUrl, finder, publisher);
                            break;
                        }
                        catch (Exception e1)
                        {
                            MyLogger.LogWarnning(e1.Message);
                            exceptionCount += 1;
                        }
                    }
                    if (exceptionCount >= 5)
                    {
                        break;
                    }
                }
                finder.driver.Quit();
            }
        }
コード例 #2
0
 static void TransferGold(DealPublisher publisher, string taskPath, Option opt)
 {
     try
     {
         GetPayee(taskPath, opt).Wait();
         publisher.TransferGold2(opt.Payee);
     }
     catch (NoSuchElementException e)
     {
         MyLogger.LogWarnning(e.Message);
     }
     catch (NullReferenceException e)
     {
         MyLogger.LogWarnning(e.Message);
     }
 }
コード例 #3
0
        public static async Task Start(string[] args)
        {
            Console.WriteLine(string.Join("\n", args));
            var opt         = LoadOption(args[0]);
            var taskPath    = args[1];
            var commandPath = args[2];
            var statusPath  = args[3];

            //var commandPath = args[4];
            Console.Title = opt.username;
            DealPublisher publisher = new DealPublisher(opt);

            if (opt.Mode == "login")
            {
                publisher.Login();
            }
            else if (opt.Mode == "smzdm_share")
            {
                publisher.Login();
                await Share(publisher, opt, taskPath, statusPath);

                Finish(publisher, opt, taskPath, statusPath);
            }
            else if (opt.Mode == "auto")
            {
                publisher.Login();
                while (true)
                {
                    await Share(publisher, opt, taskPath, statusPath);

                    Finish(publisher, opt, taskPath, statusPath);
                    await ReadCommand(commandPath, opt);

                    if (opt.Command == "stop")
                    {
                        Console.WriteLine("Stop");
                        break;
                    }
                    Console.WriteLine(DateTime.Now.ToString());
                    await Task.Delay(opt.Freq *1000);
                }
            }
            //Finish(publisher, opt, statusPath);
            publisher.driver.Quit();
        }
コード例 #4
0
 static void Finish(DealPublisher publisher, Option opt, string taskPath, string statusPath)
 {
     try
     {
         publisher.Follow();
         publisher.Punch();
         publisher.Like();
         //Console.WriteLine(opt.Payee);
         TransferGold(publisher, taskPath, opt);
     }
     catch (System.NullReferenceException e)
     {
         MyLogger.LogWarnning(e.Message);
         MyLogger.LogWarnning(e.InnerException.Message);
     }
     catch (AggregateException e)
     {
         MyLogger.LogWarnning(e.Message);
         MyLogger.LogWarnning(e.InnerException.Message);
     }
 }
コード例 #5
0
        static void FindDealAndPublish(Option option, string pageUrl, DealFinder dealFinder, DealPublisher publisher)
        {
            var smzdmItemList = new List <Dictionary <string, string> >();

            dealFinder.driver.Navigate().GoToUrl(pageUrl);
            var items = dealFinder.driver.FindElements(By.ClassName("z-feed-content")).ToList();

            foreach (IWebElement item in items)
            {
                var it = dealFinder.GetSmzdmItem(item);
                if (it != null)
                {
                    smzdmItemList.Add(it);
                }
            }


            Console.WriteLine("Collected good price count " + smzdmItemList.Count);
            foreach (var it in smzdmItemList)
            {
                var price = dealFinder.CheckPrice(it);
                if (price != null)
                {
                    price.Calculate();
                    var goodPrice      = price.SmzdmGoodPrice;
                    var sourceUrl      = price.sourceUrl;
                    var continueSubmit = publisher.PasteItemUrl(sourceUrl, 0, option.waitBaoliao, option.baoLiaoStopNumber);
                    if (continueSubmit)
                    {
                        Console.WriteLine("Continue to submit.");
                        publisher.SubmitBaoLiao(option.descriptionMode, goodPrice, 0.0, sourceUrl, option.PriceRate, 0.0, price);
                    }
                    if (publisher.baoLiaoLeft == 0)
                    {
                        Console.WriteLine("BaoLiao left 0, break.");
                        break;
                    }
                    Console.WriteLine("Move to next item");
                }
            }

            Console.WriteLine(option.Topic + " " + pageUrl + " Task Finished");
            Console.WriteLine("baoliao left " + publisher.baoLiaoLeft);
        }