如何在 RSS 源更新时触发可执行文件

发布于 2024-11-02 22:20:44 字数 504 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫卆 2024-11-09 22:20:44

正如评论者已经指出的那样,这个问题相当广泛,但这里尝试回答:

  • 您可以编写一个 Windows 服务(使用 VS/MonoDevelop 附带的模板),也可以编写一个简单的控制台应用程序,它将由 Windows Scheduler 或 Cron 调用。

  • 主代码将使用众多可用的 RSS 提要解析器之一:

这里有很多关于 SO 的示例。 IMO,最简单的基于 LINQ 的是 这里

我个人喜欢 这种方法,也使用 LINQ 。

  • 解析提要后,您需要查找 Link 元素的值,该值是通过从上面的 SO 示例中执行此操作找到的:

....

var feeds = from feed in feedXML.Descendants("item")
              select new
              {
                Title = feed.Element("title").Value,
                **Link** = feed.Element("link").Value,
                Description = feed.Element("description").Value
              };

....

  • 所以,现在您已经有了可执行文件,您需要将其下载到您的计算机上。我建议您查看 MSDN 中的此示例
  • 现在,您下载文件后,只需使用 Process.Start("Path to EXE"); 即可执行它。

小心前任中的病毒!

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.

  • Once you parse the feed, you need to look for the value of the Link element, found by doing this from the SO example above:

....

var feeds = from feed in feedXML.Descendants("item")
              select new
              {
                Title = feed.Element("title").Value,
                **Link** = feed.Element("link").Value,
                Description = feed.Element("description").Value
              };

....

  • So, now that you have the executable, you'll need to download it to your machine. I suggest you look into this example from MSDN:
  • Now, that you have the file downloaded, simple use Process.Start("Path to EXE"); to execute it.

Watch out for viruses in the exes!!!

痴情 2024-11-09 22:20:44

如果您使用 .Net 3.5 或更高版本,您可以使用 System.ServiceModel.Synmination 命名空间,特别是 SyndicateFeed 类公开 LastUpdatedTime 属性,您可以使用该属性来比较日期,以了解何时使用 System.Diagnostics 命名空间中的 Process.Start 方法。

            using (XmlReader reader = XmlReader.Create(path))
            {
                SyndicationFeed feed = SyndicationFeed.Load(reader);

                if ((feed != null) && (feed.LastUpdateTime > feedLastUpdated))
                {
                    // Launch Process                            
                }
            }

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.

            using (XmlReader reader = XmlReader.Create(path))
            {
                SyndicationFeed feed = SyndicationFeed.Load(reader);

                if ((feed != null) && (feed.LastUpdateTime > feedLastUpdated))
                {
                    // Launch Process                            
                }
            }
不如归去 2024-11-09 22:20:44

因此,您必须从 URL 读取 RSS 提要,然后解析数据以确定是否有新项目可用。

要阅读提要,您需要使用 WebClient。最简单的方法:

var MyClient = new WebClient();
string rssData = MyClient.DownloadString("http://whatever");

然后您可以根据返回的字符串创建 XML 文档。

var feedXML = new XMlDocument();
feedXML.Load(rssData);

@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:

var MyClient = new WebClient();
string rssData = MyClient.DownloadString("http://whatever");

You can then create an XML document from the returned string.

var feedXML = new XMlDocument();
feedXML.Load(rssData);

@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.

浮华 2024-11-09 22:20:44

您可以编写一个系统托盘应用程序。我已经按计划完成了几个屏幕抓取/监控站点。这是一个非常简单的开始。我想你可以在几个小时内完成你想要的事情。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文