-
-
Save Enapiuz/9d73899ce739f6bb3416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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