Created
October 8, 2016 21:34
-
-
Save sdwheeler/c7d0d11389adabe22fd9ee0f08067087 to your computer and use it in GitHub Desktop.
Examples of accessing woot.com from a PowerShell scrip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function woot { | |
param([ValidateSet('accessories','computers','electronics','home','kids','sellout','shirt','sport','tools','wine','www', ignorecase=$true)] | |
[string]$site | |
) | |
$url = 'http://api.woot.com/1/sales/current.rss' | |
if ($site -ne "") { | |
$url = "http://api.woot.com/1/sales/current.rss/{0}.woot.com" -f $site | |
} | |
$woots = Invoke-RestMethod $url | |
foreach ($woot in $woots) { | |
$wootoff = "" | |
if ($woot.wootoff -eq "true") {$wootoff = "woot!"} | |
$props = [ordered]@{ | |
site=($woot.link -split "\.")[0] -replace "http://",""; | |
title=$woot.title; | |
price=$woot.pricerange; | |
'%sold'=[double]($woot.soldoutpercentage) * 100; | |
wootoff=$wootoff; | |
condition=$woot.condition; | |
} | |
new-object -type PSObject -prop $props | |
} | |
} | |
function wootapi { | |
$apikey = "your-api-key-here" | |
$url = "https://api.woot.com/2/events.json?eventType=Daily&key={0}" -f $apikey | |
$daily = invoke-restmethod $url | |
$daily | | |
select @{l="site";e={($_.site -split "\.")[0]}}, | |
@{l="title";e={$_.offers.Title}}, | |
@{l="Price";e={$_.offers.items.SalePrice | sort | select -first 1 -Last 1}}, | |
@{l="%";e={$_.offers.PercentageRemaining}}, | |
@{l="Condition";e={$_.offers.items.Attributes | where Key -eq "Condition" | select -exp Value -first 1}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment