Category Archives: Amazon

Kindle price tracking.. First success!

My little script notified my of the first book that met the price conditions I set.

I am feeling pretty pleased with myself right now..

Here is the script I use..
Kindle Price tracking on Amazon with Powershell

Advertisements

Leave a comment

Filed under Amazon, Microsoft, Powershell

Kindle Price tracking on Amazon with Powershell

I like reading books via the Kindle app, but unfortunately, a lot of price tracking websites seem to have problems with these (perhaps something to do with stock levels?). So the obvious solution was to write something in Powershell to do this. This runs on my Windows 7 PC using Powershell 3.0, and the .NET 4.0 extended framework.

It requires a .csv file with two columns, one called URL, and one called PRICE (which contains the price you would be willing to pay), and then simply a line for each (with no currency indicator on price. So no dollar, pound, euro etc).

I have a sample here:
http://tinyurl.com/cm9zwqv

I have only tried this with amazon.co.uk, so with any other Amazon site (such as Amazon.com) I suspect it will still work, but you would need to change the currency indicate (it currently trims a “£” and that would need to be a “$” or “€”…

Then, once you have the URL and target prices for the items, simply run it manually, or you can schedule it! If the price is below your threshold, it will prompt you to go to the webpage for the product.


No more constant checking of prices!

Param([string]$itemfile="items.csv")
del "$env:userprofile\my documents\http.txt" -ea SilentlyContinue

$items = (Import-Csv -Path $itemfile)
Foreach ($item in $items) {
	$path = $item.URL 
	$TargetPrice = $item.Price
	#Open page
	$ie = New-Object -ComObject InternetExplorer.Application
	$ie.Navigate("$path")
	While ($ie.Busy) { Start-Sleep -Milliseconds 200 }
	#Read contents
	$ie.Document.body.innerhtml | Out-File "$env:userprofile\my documents\http.txt"
	#Get price
	$nowPrice = (((get-content "$env:userprofile\my documents\http.txt" `
				| where {$_ -match "priceLarge"}).Split(">"))[2].Split(" ")[0]).TrimStart("£")
	#Get title
	$title = ((get-content "$env:userprofile\my documents\http.txt" `
				| where {$_ -match "parseasinTitle"}).Split(">"))[2].Split("<")[0]
	If ($path -ne $null) {
		Write-host "Current Price of $title = $nowPrice"
		#compare price
		If ([decimal]$nowPrice -le [decimal]$TargetPrice) {
			#Go to item page?
			$GotoPage = Read-Host "Target price of $nowPrice reached for $title. Go to this items page now (y/n)"
			If ($GotoPage -eq "y") {
				$ie.Visible = $true
				}
			Else {
				$ie.quit()
				}
			}
		Else {
			$ie.quit()
			}
		}

Or get the .PS1 file here:
http://tinyurl.com/boq4uwn

1 Comment

Filed under Amazon, Microsoft, Powershell