mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-05 21:49:07 +01:00
Updated watch-news.ps1
This commit is contained in:
parent
430074a982
commit
6e27c12b46
@ -8,13 +8,13 @@
|
||||
.PARAMETER lines
|
||||
Specifies the initial number of headlines
|
||||
.PARAMETER timeInterval
|
||||
Specifies the time interval in seconds between two Web requests (30 seconds by default)
|
||||
Specifies the time interval in seconds between two Web requests (60 seconds by default)
|
||||
.EXAMPLE
|
||||
PS> ./watch-news.ps1
|
||||
|
||||
UTC Yahoo News - Latest News & Headlines - https://www.yahoo.com/news/world
|
||||
--- -----------------------------------------------------------------------
|
||||
❇️ 14:29 Niger coup: Ecowas deadline sparks anxiety in northern Nigeria
|
||||
UTC Yahoo News - Latest News & Headlines - https://www.yahoo.com/news/world
|
||||
--- -----------------------------------------------------------------------
|
||||
14:29 Niger coup: Ecowas deadline sparks anxiety in northern Nigeria
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
@ -22,31 +22,36 @@
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$URL = "https://news.yahoo.com/rss/world", [int]$timeInterval = 30) # in seconds
|
||||
param([string]$URL = "https://news.yahoo.com/rss/world", [int]$timeInterval = 60) # in seconds
|
||||
|
||||
function PrintLatestHeadlines([xml]$content, [string]$latestTimestamp) {
|
||||
function PrintLatestHeadlines([xml]$content, [string]$latestTimestamp, [string]$icon) {
|
||||
$items = $content.rss.channel.item
|
||||
[array]::Reverse($items)
|
||||
$newLatest = $latestTimestamp
|
||||
foreach($item in $items) {
|
||||
if ($($item.pubDate) -le $latestTimestamp) { continue }
|
||||
$pubDate = $item.pubDate
|
||||
if ($pubDate -le $latestTimestamp) { continue }
|
||||
$title = $item.title
|
||||
$time = $item.pubDate.Substring(11, 5)
|
||||
& "$PSScriptRoot/write-typewriter.ps1" "❇️ $time $title" 2
|
||||
$latestTimestamp = $item.pubDate
|
||||
$time = $pubDate.Substring(11, 5)
|
||||
Write-Host "$time $title$icon"
|
||||
Start-Sleep -milliseconds 500
|
||||
if ($pubDate -gt $newLatest) { $newLatest = $pubDate }
|
||||
}
|
||||
return $latestTimestamp
|
||||
return $newLatest
|
||||
}
|
||||
|
||||
try {
|
||||
[xml]$content = (Invoke-WebRequest -URI $URL -useBasicParsing).Content
|
||||
$title = $content.rss.channel.title
|
||||
$link = $content.rss.channel.link
|
||||
" "
|
||||
" UTC $title - $link"
|
||||
" --- -----------------------------------------------------------------------"
|
||||
Write-Host "`n UTC $title - " -noNewline
|
||||
Write-Host $link -foregroundColor blue
|
||||
Write-Host " --- -----------------------------------------------------------------------"
|
||||
$latestTimestamp = "2000-01-01"
|
||||
$icon = ""
|
||||
do {
|
||||
$latestTimestamp = PrintLatestHeadlines $content $latestTimestamp
|
||||
$latestTimestamp = PrintLatestHeadlines $content $latestTimestamp $icon
|
||||
$icon = "🆕"
|
||||
Start-Sleep -seconds $timeInterval
|
||||
[xml]$content = (Invoke-WebRequest -URI $URL -useBasicParsing).Content
|
||||
} while ($true)
|
||||
|
Loading…
Reference in New Issue
Block a user