Added watch-news.ps1

This commit is contained in:
Markus Fleschutz 2024-05-16 13:14:01 +02:00
parent 60cc93dbbd
commit 1f51d6ab66
3 changed files with 38 additions and 3 deletions

View File

@ -38,9 +38,8 @@ try {
if (-not(Test-Path "$path" -pathType Container)) { throw "The path to 📂$path doesn't exist (yet)" }
$path = Resolve-Path "$path"
Set-Location "$path"
"📂$path"
Write-Host "📂$path • on branch: " -noNewline
Write-Host -noNewline " on branch: "
& git status --short --branch --show-stash
exit 0 # success
} catch {

View File

@ -1,6 +1,6 @@
<#
.SYNOPSIS
List commits live in real-time.
Show commits live in real-time.
.DESCRIPTION
This PowerShell script permanently lists the latest commit in a Git repository in real-time.
.PARAMETER pathToRepo

36
scripts/watch-news.ps1 Normal file
View File

@ -0,0 +1,36 @@
<#
.SYNOPSIS
Lists the latest headlines
.DESCRIPTION
This PowerShell script lists the latest headlines by using a RSS (Really Simple Syndication) feed.
.PARAMETER RSS_URL
Specifies the URL to the RSS feed (Yahoo World News by default)
.PARAMETER maxLines
Specifies the maximum number of lines to list (24 by default)
.EXAMPLE
PS> ./list-headlines.ps1
Niger coup: Ecowas deadline sparks anxiety in northern Nigeria
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$RSS_URL = "https://news.yahoo.com/rss/world", [int]$maxLines = 24)
try {
[xml]$content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content
[int]$count = 1
foreach ($item in $content.rss.channel.item) {
& "$PSScriptRoot/write-animated.ps1" "* $($item.title) *"
if ($count++ -eq $maxLines) { break }
}
$source = $content.rss.channel.title
$date = $content.rss.channel.pubDate
" (by $source as of $date)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}