public async Task <IEnumerable <Item> > GetItemsAsync(bool forceRefresh = false) { #if DEBUG //use static feed saved in gist for testing string feedUrl = "https://gist.githubusercontent.com/RobertEves92/85e22fbe847fc4fb08e1aa28851e3bdd/raw/ba25f9d2a9ef44a17071f2507ca20726f3832f74/gistfile1.txt"; #else //use live feed from mercury for releases string feedUrl = "https://www.hertfordshiremercury.co.uk/news/?service=rss"; #endif string feedSrc = NetServices.GetWebpageFromUrl(feedUrl); feedSrc = Unescape.UnescapeHtml(feedSrc); var feed = FeedReader.ReadFromString(feedSrc); foreach (var item in feed.Items) { items.Add(new Item { Id = Guid.NewGuid().ToString(), Title = item.Title, Description = item.Description, PublishingDate = (DateTime)item.PublishingDate, Author = item.Author, Link = item.Link }); } //add keywords after loading items var keywords = Regexes.Keywords.Matches(feedSrc); for (int i = 0; i < keywords.Count; i++) { items[i].KeyWords = keywords[i].Value; } return(await Task.FromResult(items)); }
/// <summary> /// フィードを読み込み、パースして返す /// </summary> /// <param name="url"></param> /// <returns></returns> public async Task <RssReadResult> ReadAsync(string url) { HttpResponseMessage response = null; var client = httpClientFactory.CreateClient(); try { response = await client.GetAsync(url); } catch (Exception e) { return(RssReadResult.CreateFailed(e.Message)); } if (!response.IsSuccessStatusCode) { return(RssReadResult.CreateFailed($"StatusCode: {response.StatusCode}")); } var feedString = await response.Content.ReadAsStringAsync(); if (string.IsNullOrWhiteSpace(feedString)) { return(RssReadResult.CreateFailed("Rss feed empty")); } // RSSをパース var feed = FeedReader.ReadFromString(feedString); return(RssReadResult.CreateSuccess(feed)); }
/// <summary> /// Loops the whole Podcastlist an update the image from the online source /// </summary> /// <param name="list"></param> public static void RefreshImages(ObservableCollection <PodcastModel> list) { foreach (var item in list) { Feed feed = FeedReader.ReadFromString(item.OriginalDocument); item.SetImagePath(feed.ImageUrl); SaveImage(item); } }
private static Feed GetFeedFromString(string feedString) { try { return(FeedReader.ReadFromString(feedString)); } catch (Exception e) { throw new FeedReaderWrapperParseStringException(e); } }
public static async Task RunAsync(CancellationToken cancellationToken) { Console.OutputEncoding = Encoding.UTF8; var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); Func <RssDbContext> contextFactory = () => new RssDbContext(config.GetConnectionString("DefaultConnection")); _recordService = new RssRecordService(contextFactory); foreach (var rssSource in _rssSources) { Console.WriteLine(rssSource.SourceName); var itemsSaved = 0; var itemsReaded = 0; var text = await Helpers.DownloadAsync(CodeHollow.FeedReader.FeedReader.GetAbsoluteUrl(rssSource.SourceUrl)); if (text.StartsWith("\n")) { text = text.Remove(0, 1); } var feed = FeedReader.ReadFromString(text); foreach (var feedItem in feed.Items) { try { await _recordService.AddAsync(new RssRecord() { PublishDate = !string.IsNullOrEmpty(feedItem.PublishingDateString) ? DateTimeOffset.Parse(feedItem.PublishingDateString) : throw new InvalidOperationException("No publish date"), SourceUrl = rssSource.SourceUrl, NameSource = rssSource.SourceName, Description = feedItem.Description, NewsUrl = feedItem.Id, Title = !string.IsNullOrEmpty(feedItem.Title) ? feedItem.Title : throw new InvalidOperationException("No publish date") }, cancellationToken); itemsSaved++; }
private string GetInfo(string url) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3; mWebClient wc = new mWebClient(); var feedxml = wc.DownloadString(url); var reader = FeedReader.ReadFromString(feedxml); return(reader.Title); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); return(""); } }
private async void UpdateRSSContent() { using (var httpClient = new HttpClient()) { httpClient.Timeout = TimeSpan.FromSeconds(15); try { await Dispatcher.InvokeAsync(() => { NothingFound.PanelType = Core.Controls.ResultPanelType.Loading; NothingFound.Visibility = Visibility.Visible; FeedItems.Clear(); }); var rss = await httpClient.GetStringAsync(RSS_Feed); Feed feed = FeedReader.ReadFromString(rss); await Dispatcher.InvokeAsync(() => { foreach (FeedItem item in feed.Items) { MCNetFeedItemRSS new_item = new MCNetFeedItemRSS(item); FeedItems.Add(new_item); NothingFound.Visibility = Visibility.Collapsed; } }); if (FeedItems.Count == 0) { NothingFound.Visibility = Visibility.Visible; } } catch (Exception ex) { await Dispatcher.InvokeAsync(() => { NothingFound.PanelType = Core.Controls.ResultPanelType.Error; NothingFound.Visibility = Visibility.Visible; }); } } }
private async Task <List <FeedItem> > GetNewItems(FeedConfig feedConfig) { Feed feed; if (!feedConfig.RequireAuth) { feed = await FeedReader.ReadAsync(feedConfig.Link); } else { // Basic HTTP auth _webClient.Credentials = new NetworkCredential(feedConfig.Username, feedConfig.Password); var response = _webClient.DownloadString(feedConfig.Link); feed = FeedReader.ReadFromString(response); } var lastUpdate = _lastUpdates[feedConfig]; if (lastUpdate is null) { _lastUpdates[feedConfig] = feed.LastUpdatedDate; return(null); } // If latest item is older than latest stored item, continue if (lastUpdate > feed.LastUpdatedDate) { return(null); } _lastUpdates[feedConfig] = feed.LastUpdatedDate; return(feedConfig.Filter is null ? feed.Items.Where(x => x.PublishingDate > lastUpdate).ToList() : feed.Items.Where(x => x.PublishingDate > lastUpdate && feedConfig.Filter.Any(x.Title.Contains)).ToList()); }