Zeaun.com
  • Support
Zeaun.com
  • Support
Information Technology Mastery,

Reading Reddit News via PowerShell

by zupreme7 months agono comment
2
Shares
Share on FacebookShare on Twitter
invoke-6
The “Meat” of the method

The provided image gives you the core of the method, but I will elaborate further for the “Uninitiated”.

Many websites publish their content, or a subset thereof, as RSS feeds. RSS means “Really Simple Syndication” and is a structured methodology for offering news and articles in a format which standardized for access and interpretation by multiple viewers and viewing platforms.

This is not to say that the full content of most news sites is available via this method, however. Far from it. In fact many news sources limit the number of characters, lines, or even which articles are contained within the Feed.

Many news sources made the above shift (to limited Feed content) as a result of “content theft” (as they saw it) but other websites who were, in many cases, accused of wholesale copying of content from source sites.

But, enough about that. Today we will cover how you can use PowerShell to read the headlines and content from Reddit’s World News Subreddit, starting with the “Invoke-Restmethod” commandlet.

Invoke-RestMethod
[-Method ]
[-FollowRelLink]
[-MaximumFollowRelLink ]
[-ResponseHeadersVariable ]
[-StatusCodeVariable ]
[-UseBasicParsing]
[-Uri]
[-WebSession ]
[-SessionVariable ]
[-AllowUnencryptedAuthentication]
[-Authentication ]
[-Credential ]
[-UseDefaultCredentials]
[-CertificateThumbprint ]
[-Certificate ]
[-SkipCertificateCheck]
[-SslProtocol ]
[-Token ]
[-UserAgent ]
[-DisableKeepAlive]
[-TimeoutSec ]
[-Headers ]
[-MaximumRedirection ]
[-MaximumRetryCount ]
[-RetryIntervalSec ]
[-Proxy ]
[-ProxyCredential ]
[-ProxyUseDefaultCredentials]
[-Body 

This utility has a lot of options, but for today we will keep it simple with “$z = invoke-restmethod https://www.reddit.com/r/worldnews/.rss”.

The first part “$z = ” captures whatever follows it as a variable or (as I think of it) a pseudo-object which can later be reused much more easily than retyping the entire command and without repeated calls to the target server (a “great” way to get IP banned).

The second part is the commandlet itself, while the third represents the path to the RSS feed we will pull data from.

Once you have the data you can display the basics from it by simply typing “$z” and pressing enter. You should see something similar to the following:

The basic results of the method

I am sure the visionaries among you already see the benefits of this method, and are already mentally Designing new ways to view the news – but don’t go yet. Let’s unpack these results first.

The First Result, i.e. [0]

By invoking “$z[0]” we only display/unpack the first result in the result set. let’s go deeper.

The “Title” in isolation

By running $z[0].title we get only the title text, without all the other fluff. Now let’s list only the titles for all articles.

Titles on Titles on Titles

The above gets us the titles, but looks like a jumble snd may be difficult to read for many. Let’s make it prettier.

25 news titles – with numbering via PowerShell

Much better. Each title on its own line with a sequence number assigned. From here one could export the data to CSV, to XML, or even to push the data to a separate server for archiving, display, or delivery.

This is a simplistic example, intended to provide those who are ready with a basic PowerShell skill, which may empower you to create your next software and/or scripting masterpiece.

Now, go use your newfound powers for Good instead of Evil. ✋🏾

Next

Getting Latitude and Longitude for a given Zip Code with PowerShell

7 months ago

Leave a Reply Cancel reply

Related posts

pop1
Information Technology Mastery,

PowerShell Tutorial: Programmatically Retrieving the Population of each US State

by zupreme7 months agono comment
coin10
Information Technology Mastery,

Tutorial: Getting the current price of Bitcoin using Powershell (USD, EUR, & GBP)

by zupreme7 months agono comment
image-12
Information Technology Mastery,

Tutorial: Public IP Address Identification with PowerShell

by zupreme7 months agono comment
image-3
Information Technology Mastery,

Browsing NASA’s Image of The Day Archive using PowerShell

by zupreme7 months agono comment

© 2020 Zeaun Zarrieff. All rights reserved.