Esempio n. 1
0
        static void apiTrackerSender()
        {
            _ctx    = new RabbitContext().Create("cv.localhost.json");
            _sender = new RmqSender(_ctx);
            _session.Sender.SetRoutingKey("cvApiTracker", "cvApiTracker");

            while (true)
            {
                Console.WriteLine("(apiTrackerSender) press enter to send another message...");
                Console.ReadLine();
                CoronaVirusApiTrackerMessage msg = CallApi().Result;
                // _session.Sender.Send(msg);
                _sender.SendMessage(msg);
            }
        }
Esempio n. 2
0
        static void sendScrapeMessage()
        {
            _ctx    = new RabbitContext().Create("cv.scraper.json");
            _sender = new RmqSender(_ctx);

            int cnt = 0;

            while (true)
            {
                cnt++;
                _sender.SendMessage(new CoronaVirusScrapeMessage());
                Console.WriteLine("press enter to send another message...", cnt.ToString());;
                Console.ReadLine();
            }
        }
Esempio n. 3
0
        static void emailSender()
        {
            _ctx    = new RabbitContext().Create("cv.localhost.json");
            _sender = new RmqSender(_ctx);

            var message = new EmailMessage()
            {
                Subject    = "subject here",
                Body       = "new email body",
                IsBodyHtml = false,
                Recipients = new List <string>
                {
                    { "*****@*****.**" },
                    { "*****@*****.**" },
                }
            };

            _sender.SendMessage(message);
        }
 public void Send(EmailMessage msg)
 {
     _sender.SendMessage(msg);
 }
        private void scrapeAndSend()
        {
            string html    = "";
            var    browser = new Browser();
            var    url     = _scrapeConfig.CoronaVirusScrape.ScrapeUrl;
            var    ss      = "https://docs.google.com/spreadsheets";

            var web = new HtmlWeb();
            var doc = web.Load(url);

            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//iframe[@src]");

            foreach (var node in nodes)
            {
                HtmlAttribute attr = node.Attributes["src"];
                if (attr.Value.ToLower().StartsWith(ss))
                {
                    url = attr.Value;
                    break;
                }
            }

            var fpath = @"C:\devApps\data\coronavirus\html";

            web = new HtmlWeb();
            doc = web.Load(url);

            html = doc.Text;
            var fname = string.Format("{0}-bno.html", DateTime.Now.ToString("yyyy.MM.dd.hh.mm.tt"));

            File.WriteAllText(Path.Combine(fpath, fname), html);

            //*[@id="0"]/div/table
            var sheet     = doc.DocumentNode.SelectSingleNode("//*[@id='sheets-viewport']").InnerHtml;
            var htmlTable = doc.DocumentNode.SelectSingleNode("//*[@id='0']/div/table").InnerHtml;
            var cases     = doc.DocumentNode.SelectSingleNode("//*[@id='0']/div/table/tbody/tr[5]/td[1]").InnerHtml;
            var deaths    = doc.DocumentNode.SelectSingleNode("//*[@id='0']/div/table/tbody/tr[5]/td[2]").InnerHtml;
            var recovered = doc.DocumentNode.SelectSingleNode("//*[@id='0']/div/table/tbody/tr[5]/td[3]").InnerHtml;
            var disp      = string.Format("Cases: {0}  Deaths: {1}  Recovered: {2}", cases, deaths, recovered);

            if (this._scrapeCache.PreviousCVscrapeValue != disp)
            {
                dumpToConsole(doc, true);

                var rowData = parseAndDump(doc);

                // send scrape notice
                _sender.SendMessage(new CoronaVirusScrapeMessage());

                // send email notice
                this._scrapeCache.PreviousCVscrapeValue = disp;
                body = string.Format("<h2>{0}:<br>{1}</h2>", DateTime.Now, disp);

                // WriteLine("{0} {1} CHANGED", DateTime.Now, disp);
                //
                List <string> recipients = new List <string> {
                    { "*****@*****.**" },
                    { "*****@*****.**" },
                    { "*****@*****.**" }
                };

                Gmail.Send(subject, body, recipients, true);
            }
            else
            {
                dumpToConsole(doc, false);
                // WriteLine("{0} {1} no change", DateTime.Now, disp);
            }
        }