Exemplo n.º 1
0
        public DateTimeOffset ReadLastProcessedDate()
        {
            var range = $"{_sheet}!B2";

            SpreadsheetsResource.ValuesResource.GetRequest request =
                _service.Spreadsheets.Values.Get(_spreadsheetId, range);

            var response = request.Execute();
            IList <IList <object> > values = response.Values;

            if (values != null && values.Count == 1)
            {
                var            row    = values[0];
                string         result = row[0].ToString();
                DateTimeOffset dt;
                if (DateTimeOffset.TryParse(result, out dt))
                {
                    _log.Debug($"last processed date = {dt}");
                    return(dt);
                }
                else
                {
                    _log.Error($"unable to parse {result}");
                    return(DateTimeOffset.Now);
                }
            }
            _log.Error("last processed date not found");
            return(DateTime.MaxValue);
        }
Exemplo n.º 2
0
        public async Task <bool> Run()
        {
            this._logger.Debug("RUN");
            var rssItems = await _rss.GetNewsFeed();

            var           lastCheckedDate = this._google.ReadLastProcessedDate();
            var           listOfInterest  = this._google.ReadWatchList();
            var           maxCheckedDate  = lastCheckedDate;
            StringBuilder mailbody        = new StringBuilder();
            StringBuilder plaintext       = new StringBuilder();

            this._logger.Debug($"found {rssItems.Count} items");
            int count = 0;

            foreach (var item in rssItems)
            {
                if (item.IsOfInterest(listOfInterest, lastCheckedDate))
                {
                    count++;
                    mailbody.AppendLine(item.GetMailBody());
                    plaintext.AppendLine(item.title);
                }
                if (maxCheckedDate < item.pubDateAsDt)
                {
                    maxCheckedDate = item.pubDateAsDt;
                }
            }
            _logger.Debug($"found {count} interesting items");
            this._google.WriteLastProcessedDate(maxCheckedDate);
            if (count > 0)
            {
                return(await this._sendgrid.SendMail("EzTvWatcher", mailbody.ToString(), plaintext.ToString()));
            }
            return(true);
        }