Skip to content

Instantly share code, notes, and snippets.

@Enapiuz
Created October 27, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Enapiuz/9d73899ce739f6bb3416 to your computer and use it in GitHub Desktop.
Save Enapiuz/9d73899ce739f6bb3416 to your computer and use it in GitHub Desktop.
using (var db = new NewsContext())
{
while (true)
{
XmlReader Reader = XmlReader.Create(original.Url);
SyndicationFeed Feed = SyndicationFeed.Load(Reader);
int totalNewAdded = 0;
foreach (SyndicationItem FeedItem in Feed.Items)
{
News item = new News();
item.Original = FeedItem.Links.First().Uri.OriginalString;
//...
try
{
HtmlWeb webget = new HtmlWeb();
HtmlDocument doc = webget.Load(item.Original);
// тут дергается источник
}
catch (System.Net.WebException wex) {
//...
}
db.News.Add(item);
try
{
db.SaveChanges();
totalNewAdded++;
} catch (Exception ex) { }
}
if (totalNewAdded > 0)
{
Console.WriteLine("New posts added: {0} from {1}", totalNewAdded, original.Url);
}
Feed = null;
Reader = null;
Thread.Sleep(60000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment