分析RSS,如果日期匹配当前日期,然后继续下载



如果RSS Updated标头的更新与当前运行的日期相匹配,则检查RSS提要的<updated> </updated>,然后继续下载。

示例RSS提要:

<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text"> Updates</title>
<subtitle type="html"><![CDATA[Latest  updates]]></subtitle>
<link href="http://website/website.rss"></link>
<id>http://website</id>
<link rel="alternate" type="text/html" href="http://website/website.rss" ></link>
<link rel="self" type="application/atom+xml" href="https://website/site/download" ></link>
<logo>http://website/website</logo>
<updated>2020-03-28 T17:32:48+00:00</updated>
<entry>
<author>
<name>ueam</name>
</author>
<title type="text"><![CDATA[2.0.4516]]></title>
<link rel="alternate" type="text/html" href="https://website/site/download"></link>
<id>https://website/site/download</id>
<summary type="html"><![CDATA[<ul>
<li>Patched for March 23rd update</li>
<li>Fixed known bug JIRA</li>
</ul>]]></summary>
<content type="html"><![CDATA[]]></content>
<updated>2020-03-28 17:32:48</updated>
</entry>
<entry>
<author>
<name>Team</name>
</author>
<title type="text"><![CDATA[2.0.4516]]></title>
<link rel="alternate" type="text/html" href="https://website/site/download"></link>
<id>https://website/site/download</id>
<summary type="html"><![CDATA[<ul>
<li>
Patch for March 23rd update 
</li>
</ul>]]></summary>
<content type="html"><![CDATA[]]></content>
<updated>2020-03-28 17:32:48</updated>
</entry>
<entry>
<author>
<name>Team</name>
</author>
<title type="text"><![CDATA[2.0.4514]]></title>
<link rel="alternate" type="text/html" href="https://website/site/download></link>
<id>https://website/site/download</id>
<summary type="html"><![CDATA[<ul>
<li>Fixed Bug</li>

此处

<updated>2020-03-28 17:32:48</updated>

显示了如果我今天运行,那么将继续下载,因为它与当天的匹配

下载将通过调用

Invoke-WebRequest -uri https://website/site/download

我只是不知道如何解析RSS以查看"更新的"并与当前日期进行比较,如果日期匹配,则继续下载。

更新:我尝试了以下

#Grab RSS
$rssString = Invoke-WebRequest "http://website/website.rss"
# convert rss to xml
$xml = [xml] $rssString
# select the <updated> node
$updateString = $xml.SelectSingleNode("/feed/updated").innerText
# convert string to date
$date = Get-Date $updateString
# compare to todays date
if($date.Date -eq (Get-Date).Date){
# proceed to download
}

您收到以下错误:Get-Date:无法将参数"Date"绑定到目标。设置"日期"时出现异常:"无法将null转换为类型"System.DateTime"。">

当你运行

$updatestring

没有返回任何内容并且为空,似乎更新的节点没有被读取

RSS是xml,所以这样对待它:(

<feed>下的<updated>节点似乎反映了最新的更新,因此请注意:

# convert rss to xml
$xml = [xml]$rssString; 
# select the <updated> node
$updateString = $xml.SelectSingleNode("/feed/updated").innerText
# convert string to date
$date = Get-Date $updateString
# compare to todays date
if($date.Date -eq (Get-Date).Date){
# proceed to download
}

相关内容

最新更新