コード例 #1
0
        /// <summary>
        ///     Scrapes the winning results for LottoMax with help from base class.
        /// </summary>
        /// <returns></returns>
        public async Task ScrapeLotteryAsync()
        {
            var lotteryUrl = "http://*****:*****@class='panel-group category-accordion-LottoMax']");

            var newLottoNumList = new List <string>();

            // Create a temporary list to store the lottery numbers.
            var tempList = lottoMax.Descendants("li").Select(x => x.InnerText).ToList();

            // Temporary list is then used to remove any leading 0s the website may have used. Json doesn't like leading 0s on numbers (f**k 'im).
            foreach (var itm in tempList)
            {
                var newItm = itm.Replace(itm, itm.TrimStart(new[] { '0' }));
                newLottoNumList.Add(newItm);
            }
            var bonusNum = newLottoNumList.Last();

            newLottoNumList.Remove(bonusNum);

            var lottoMaxDrawNums = string.Join(", ", newLottoNumList);

            var newResults = await _formatNewLotteryResult.FormatResult(lottoMaxDrawNums, bonusNum);

            _writeNewResult.NewLotteryResultsWritten += _afterLottoWritten.OnResultsWritten;
            var   writeTask = Task.Run(() => _writeNewResult.WriteNewResults("LottoMax", newResults));
            await writeTask;
        }
コード例 #2
0
        /// <summary>
        ///     Scrapes the winning results for Lotto649 with help from base class.
        /// </summary>
        /// <returns></returns>
        public async Task ScrapeLotteryAsync()
        {
            var    lotteryUrl = "https://powerball.com/api/v1/numbers/powerball/recent?_format=json";
            string powerballJson;

            using (var client = new HttpClient())
            {
                powerballJson = await client.GetStringAsync(lotteryUrl);
            }

            JArray powerballData   = JArray.Parse(powerballJson);
            var    newLottoNumList = new List <string>();

            // Create a temporary list to store the lottery numbers.
            string[] tempList = powerballData[0]["field_winning_numbers"].ToObject <string>().Split(',');

            // Temporary list is then used to remove any leading 0s the website may have used. Json doesn't like leading 0s on numbers (f**k 'im).
            // Also removes the last number (bonus number) and separates it out into a new variable.

            foreach (string itm in tempList)
            {
                string newItm = itm.Replace(itm, itm.TrimStart(new[] { '0' }));
                newLottoNumList.Add(newItm);
            }
            string bonusNum = newLottoNumList.Last();

            newLottoNumList.Remove(bonusNum);

            string usPowerballNums = string.Join(", ", newLottoNumList);

            string newResults = await _formatNewLotteryResult.FormatResult(usPowerballNums, bonusNum);

            _writeNewResult.NewLotteryResultsWritten += _afterLottoWritten.OnResultsWritten;
            Task  writeTask = Task.Run(() => _writeNewResult.WriteNewResults("USPowerball", newResults));
            await writeTask;
        }