Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun: Holiday Shopping with PowerShell

Posted on November 27, 2015November 27, 2015

Once again, the holiday shopping season is upon us. But perhaps PowerShell can make it a little easier or at least a bit more fun. I'm sure many of you have shopped at NewEgg.com. Perhaps you plan to do so again this year for friends, family or even yourself. So why not let PowerShell make this a bit easier.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

NewEgg is savvy enough to publish RSS feeds for a number of their sales categories. You can find a master list at http://www.newegg.com/RSS/Index.aspx.  Let's take their Deal of the Day feed.

$uri = "http://www.newegg.com/Product/RSS.aspx?Submit=RSSDailyDeals&Depa=0"

Using Invoke-RestMethod, it is very easy to retrieve items.

Invoke-RestMethod -Uri $uri

But it is still a bit of a jumble, so let's get a bit more selective.

$data = Invoke-RestMethod -Uri $uri | Select -property @{Name="Published";Expression= {$_.pubDate -as [datetime]}},Title,Link

I also created a new property called Published which takes the original PubDate and treats it as a date which makes the data easier to sort or filter.

Here's a sample of what I retrieved.

A NewEgg Deal of Day itemA NewEgg Deal of Day item (Image Credit: Jeff Hicks)

With this data, I can use Out-Gridview as an object-picker.

$data | out-gridview -Title "Deal of the Day" -OutputMode Multiple | foreach { Start $_.link }

Links in Out-GridviewLinks in Out-Gridview (Image Credit: Jeff Hicks)

I can select multiple entries, click OK and each link should open up in my browser.

The online dealThe online deal (Image Credit: Jeff Hicks)

But let's make things a bit more interesting. The Title property includes the price and description. I have no idea what these links look like in other parts of the world so you may have to adjust the following examples.

First, I'm going to define a regular expression pattern to use named captures to get the currency, in my case $, the price and the item description.

[regex]$rx = "(?<currency>.)(?<price>\d+\.\d{2})\s-\s(?<item>.*)"

I'm going to re-download the data skipping any entry that doesn't have what looks like a price in the title field.

$dl = Invoke-RestMethod -Uri $uri | where {$_.Title -match "\d+\.\d{2}"}

My goal is to use Out-Gridview again with separate properties for the currency and price. I need the price to be numeric so that I can sort on it. I next get the currency symbol using the regex expression.

$c = $rx.match($dl[0].title).groups["currency"].value

Then I can process the rest of the RSS data, using the regex object to parse out the price and description.

$data = $dl |
Select -property @{Name="Published";Expression= {$_.pubDate -as [datetime]}},
@{Name=$c;Expression = {$rx.match($_.title).groups["price"].value -as [double]}},
@{Name="Item";Expression = {$rx.match($_.title).groups["item"].value }},
Link

If you notice, I used the Currency value as a property name. Now when I use Out-Gridview I have a more flexible display.

$data | Sort $c –descending | Out-GridView -Title $uri -OutputMode Multiple |
foreach {
#open each selected link
start $_.link
}

Reformatted DealsReformatted Deals (Image Credit: Jeff Hicks)

If I'm shopping for a new laptop, I can select multiple entries, click OK and review them in my browser.

Viewing my choicesViewing my choices (Image Credit: Jeff Hicks)

I can repeat the process by changing the RSS feed, say to their Shell Shocker

$uri = "http://www.newegg.com/Product/RSS.aspx?Submit=ShellShocker"

If I repeat the previous steps, this will fail, which brings up something to keep in mind with regular expressions: know your data. You have to know what you are processing and that it follows a predictable pattern. At least if you want to keep your regular expression patterns relatively simple. The problem here is that there is only a single item. So my code to get the currency figure fails, because I don't have an array. In this situation I could do this:

$c = $rx.match($dl.title).groups["currency"].value

Although it might make more sense to come up with code that I can re-use.

$entry = $dl | select -first 1
$c = $rx.match($dl.title).groups["currency"].value

But from here the code is the same.

Shell Shocker itemShell Shocker item (Image Credit: Jeff Hicks)

That might be something I want to look into, although sometimes the RSS feeds are bit behind the site. Sadly, in this case, the link works, but the product is something else. But you get the idea.

Enjoy your holiday weekend and be careful out there!


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “Friday Fun: Holiday Shopping with PowerShell”

  1. Prateek Singh says:
    November 27, 2015 at 8:29 pm

    Exactly the stuff I like, Simply awesome!

  2. Isaac V. says:
    December 11, 2015 at 12:43 pm

    Very interesting article. I’ve never been good with URI calls, so this is a neat and practical tutorial.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d