示例#1
0
        public static void BeginMonitoring(MongoCRUD db)
        {
            //Settup new Chrome client with Selenium
            var options = new ChromeOptions();

            options.AddArguments("--disable-gpu");
            var chromeDriver = new ChromeDriver(options);

            //Create records for youtubers not in the database
            foreach (string ytr in youtubers)
            {
                if (db.LoadRecords <YoutuberModel>("Youtubers").Count == 0 || db.recordExists <YoutuberModel>("Youtubers", ytr) == false)
                {
                    db.InsertRecord("Youtubers", CreateYoutuber(ytr));
                }
            }


            //Update records of youtubers
            foreach (string ytr in youtubers)
            {
                var oneRec = db.LoadRecrdByUrl <YoutuberModel>("Youtubers", ytr);

                UpdateLatestPost(chromeDriver, oneRec);
                UpdateLatestVideo(chromeDriver, oneRec);
            }

            //Console.WriteLine("Name: " + oneRec.name + " Last Post: " + oneRec.latestPost);
            chromeDriver.Close();
        }
示例#2
0
        static void Main(string[] args)
        {
            //Create Mongo databases
            db = new MongoCRUD("YoutuberBook");

            var startTimeSpan  = TimeSpan.Zero;
            var periodTimeSpan = TimeSpan.FromMinutes(1);

            Console.Write("Scanning....");

            //WRITE TO TEXT FILE
            string docPath = AppDomain.CurrentDomain.BaseDirectory;

            using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "log.txt")))
            {
                outputFile.WriteLine("Scanning has started....");
            }

            //END OF TEXT FILE



            BeginMonitoring(db);
            Console.WriteLine("Last update at: " + DateTime.UtcNow.ToString("G"));


            using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "log.txt")))
            {
                outputFile.WriteLine("Scanning has FINISHED....");
            }

            //var timer = new System.Threading.Timer((e) =>
            //{

            //    BeginMonitoring(db);
            //    Console.WriteLine("Last update at: " + DateTime.UtcNow.ToString("G"));
            //}, null, startTimeSpan, periodTimeSpan);


            // _quitEvent.WaitOne();
        }