Exemple #1
0
        private async Task <string> TryGetIstuWeekStatusFromIstuWithBrowserEmulation(string istuUrl)
        {
            var resp = await _network.GetAsync(istuUrl, useBrowserEmulation : true);

            if (resp.IsSuccessStatusCode)
            {
                var doc = new HtmlDocument();
                doc.LoadHtml(await resp.Content.ReadAsStringAsync());
                var weekHtmlNode = doc.DocumentNode.
                                   SelectSingleNode("//div[contains(@class, 'site-header-top-element ref-week type-separated')]");

                var istuWeekStatus = weekHtmlNode?.InnerText;
                return(istuWeekStatus);
            }

            return(null);
        }
Exemple #2
0
        public async Task <Stream> GetCatPictureAsync()
        {
            var queryEndpoint = $"https://api.thecatapi.com/v1/images/search/?api_key={_config.Config.CatApiKey}";

            #region Expected json responce type

            /*
             *  Expected json responce type:
             *  [
             *  {
             *      "breeds": [],
             *      "id": "avh",
             *      "url": "https://cdn2.thecatapi.com/images/avh.jpg",
             *      "width": 500,
             *      "height": 313
             *  }
             *  ]
             */
            #endregion

            var type = new[]
            {
                new
                {
                    url = "",
                }
            };

            // get responce from an api, then go to picture page and get it

            var apiResponce = await _worker.GetDeserializedAsync(queryEndpoint, type);


            Stream result = null;
            if (apiResponce.HttpResponseMessage.IsSuccessStatusCode)
            {
                var imgStream = await(
                    await _worker.GetAsync(apiResponce.DesirializedContent.FirstOrDefault().url)
                    ).Content.ReadAsStreamAsync();

                result = imgStream;
            }

            return(result);
        }