LoginSignup
1
4

More than 3 years have passed since last update.

PowerShellでRSSフィードを取得

Posted at

新しい言語を覚える際は、自分が他の言語で書いたツールを移植してみることから始めることにしている。

そんなわけで、前にPythonで書いたRSSリーダ(マルチコア対応)を書き換えてみた。本当はマルチコアで動かしたかったが、MacOSで動くPowerShellではworkflowが実装されてないので、とりあえずシングルスレッドで動かす。

#!/usr/local/bin/pwsh 
$regex = Read-Host "keyword"

$urls =@(
    'https://gizmodo.com/rss',
    'https://www.cnet.com/rss/all/',
    'https://techcrunch.com/feed/'
)

foreach ( $url in $urls ){
    $f = [XML](Invoke-WebRequest $url)
    foreach( $item in $f.rss.channel.item ) {
        if ($item.description -match $regex ){
            Write-Host $item.title
            Write-Host $item.link
            Write-Host ""
        }
    }
}

お気付きの通り、かなりシンプル。特にXMLが信じられないほど楽だ。

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4