如何在 RSS 源更新时触发可执行文件
我有一个 RSS 源 URL,可以在任何源阅读器中查看。
此 RSS 提要不受我控制,它仅由我使用。
此 RSS 源 (监察长办公室的排除提供商列表) 链接到页面带有可下载的文件。
这些文件大约每月更新一次,并且 RSS 源会显示新的“未读”项目。
我想要做的是编写一些东西(用 C#)每周检查一次此 RSS 提要,并且当新项目(即新的可下载文件)可用时,触发可执行文件。
这本质上就像一个缩小版的 RSS 阅读器,其唯一目的是在新项目出现时触发可执行文件。
任何指导、建议将不胜感激。
编辑:
- 我需要帮助来确定何时需要新的 项目可用于 下载。
- 的运行 可执行文件我可以做。
- 这 将运行、将处理的可执行文件 下载的文件。
I have an RSS feed URL, that I can view in any Feed Reader.
This RSS feed is not controlled by me, it is only consumed by me.
This RSS Feed (Office of Inspector General's Excluded Provider List) links to a page with download-able files.
These files are updated approximately once a month, and the RSS feed displays new "unread" items.
What I want to do is write something (in C#) that checks this RSS Feed once a week, and when a new item (i.e. a new download-able file) is available, triggers off an executable.
This is essentially like a very scaled-down RSS Reader, with the sole purpose of triggering an executable when a new item appears.
Any guidance, advice would be greatly appreciated.
Edit:
- I need help in determining when a new
item becomes available for
download. - The running of an
executable I can do. - The
executable that will run, will process
the downloaded file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如评论者已经指出的那样,这个问题相当广泛,但这里尝试回答:
您可以编写一个 Windows 服务(使用 VS/MonoDevelop 附带的模板),也可以编写一个简单的控制台应用程序,它将由 Windows Scheduler 或 Cron 调用。
主代码将使用众多可用的 RSS 提要解析器之一:
这里有很多关于 SO 的示例。 IMO,最简单的基于 LINQ 的是 这里
我个人喜欢 这种方法,也使用 LINQ 。
Link
元素的值,该值是通过从上面的 SO 示例中执行此操作找到的:....
....
小心前任中的病毒!
As a commenter already noted, this question is quite broad, but here's an attempt to answer:
You can either write a Windows Service (use a template that comes with VS/MonoDevelop) or you can write a simple console app that would be called by Windows Scheduler or Cron.
The main code will use one of the many RSS feed parsers available:
There are plenty of examples here on SO. IMO, the simplest LINQ-based is here
I personally like this approach, also using LINQ.
Link
element, found by doing this from the SO example above:....
....
Process.Start("Path to EXE");
to execute it.Watch out for viruses in the exes!!!
如果您使用 .Net 3.5 或更高版本,您可以使用 System.ServiceModel.Synmination 命名空间,特别是 SyndicateFeed 类公开 LastUpdatedTime 属性,您可以使用该属性来比较日期,以了解何时使用 System.Diagnostics 命名空间中的 Process.Start 方法。
If you are using .Net 3.5 or above you can you the various classes within the System.ServiceModel.Syndication namespace, specifically the SyndicationFeed class which exposes a LastUpdatedTime property that you can use to compare dates to know when to call your executable using the Process.Start method in the System.Diagnostics namespace.
因此,您必须从 URL 读取 RSS 提要,然后解析数据以确定是否有新项目可用。
要阅读提要,您需要使用 WebClient。最简单的方法:
然后您可以根据返回的字符串创建 XML 文档。
@dawebber 展示了如何使用 LINQ 解析 XML。您需要检查每个项目的日期,看看它是否比上次检查的日期新。或者,您可能有一个包含您已经见过的项目的数据库,并且您想要检查您收到的项目是否在数据库中。
每当您找到新项目时,都可以使用 进程.开始。
So you have to read the RSS feed from the URL, and then parse the data to determine whether a new item is available.
To read the feed, you'll want to use a WebClient. The simplest way:
You can then create an XML document from the returned string.
@dawebber shows how to parse the XML with LINQ. You'll want to check the date on each item to see if it's newer than the last date checked. Or perhaps you have a database of items that you've already seen and you want to check to see if the items you received are in the database.
Whenever you find a new item, you can fire off your executable using Process.Start.
您可以编写一个系统托盘应用程序。我已经按计划完成了几个屏幕抓取/监控站点。这是一个非常简单的开始。我想你可以在几个小时内完成你想要的事情。
http://alperguc.blogspot.com /2008/11/c-system-tray-minimize-to-tray-with.html
You could write a System Tray application. I've done several that screen scrape/monitor sites on a scheduled basis. Here is a VERY simple start. I think you could do what you're looking for in a few hours.
http://alperguc.blogspot.com/2008/11/c-system-tray-minimize-to-tray-with.html