Git Product home page Git Product logo

pskindlewatch's Introduction

PSKindleWatch

version

PSKindleWatch is a PowerShell module that keeps a Kindle book watchlist and can alert you when a price drop occurs.

Installation

Via PowerShell Gallery

Install-Module -Name PSKindleWatch -Scope CurrentUser

Via Git

Clone the repository and run .\build.ps1 deploy.

This will install several modules if you do not already have them, see build.ps1 for details. These are only required for the build process and are not otherwise used by PSKindleWatch.

Manually

Copy the files from src to C:\Program Files\WindowsPowerShell\Modules\PSKindleWatch and rename the .ps1 file to .psm1.

Running

PSKindleWatch only has 4 cmdlets

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Add-KindleBook                                     1.0        PSKindleWatch
Function        Get-KindleBooks                                    1.0        PSKindleWatch
Function        Remove-KindleBook                                  1.0        PSKindleWatch
Function        Update-KindleBookPrices                            1.0        PSKindleWatch

Add-KindleBook

Add-KindleBook -BookURL <String> [-DataFile <String>]

Please ensure the URL is of the Kindle edition of the book, others may not work due to differences in Amazon's APIs.

Kindle edition

The module stores book data in a JSON file, the -DataFile parameter specifies the path to this file. It is an optional parameter, by default it will be placed in the user's Documents folder and named KindleBooks.json.

Example

Add-KindleBook -BookURL "https://www.amazon.com.au/dp/B07YX3B5G9/"

Get-KindleBooks

Get-KindleBooks [-DataFile <String>]

Returns a list of currently monitored books.

Example

PS C:\> Get-KindleBooks | Format-Table -AutoSize

Title                                                                                            Authors                               OriginalPrice
-----                                                                                            -------                               -------------
The Age of Surveillance Capitalism: The Fight for a Human Future at the New Frontier of Power    Shoshana Zuboff                                9.80
Superforecasting: The Art and Science of Prediction                                              Philip Tetlock,Dan Gardner                    14.99
Naked Economics: Undressing the Dismal Science (Fully Revised and Updated)                       Charles J. Wheelan, Burton G. Malkiel         23.06

Remove-KindleBook

Remove-KindleBook -BookTitle <String>

The title lookup uses -match, a partial string match will suffice.

Example

PS C:\> Remove-KindleBook -BookTitle narco
Removing:
 -Narconomics: How To Run a Drug Cartel

Update-KindleBookPrices

Update-KindleBookPrices [-DataFile <String>] [-AlertScriptBlock <ScriptBlock>]

Checks the current price of all books in the data file and prints any price drop to the console.

It is recommended a wrapper be created to run this in a loop in a PowerShell window, or as a scheduled task, or as a Windows Service. I've written up a quick guide on how it can be made to run as a service to avoid needing to manually restart the process after reboots. Check it out here.

Example

while($true) {
    Get-Date
    Update-KindleBookPrices
    Start-Sleep -Seconds 43200
}

Example Output

PS C:\> Update-KindleBookPrices
Checking price of Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell
+Found discount for Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell, new price is $41.98 (original: $67.91)

Alerting

As there are many options for alerting (email, SMS, push, API, ...) and each one with a myriad of providers this functionality has been left to the user to implement.

The Update-KindleBookPrices accepts a ScriptBlock parameter called -AlertScriptBlock. The ScriptBlock is executed if there is a change in price, and gets passed the $Book object (see JSON representation below) as the first parameter, and a descriptive message (a string, see example above in green) as the second parameter.

{
    "ASIN":  "B00ARN9MEK",
    "Title":  "Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell",
    "Authors":  [
                    "Lee Holmes"
                ],
    "URL":  "https://www.amazon.com.au/Windows-PowerShel...<truncated>",
    "ImageURL":  "https://images-na.ssl-images-amazon.com/images/I/51MtlVpXnvL.jpg",
    "IsOnSale":  true,
    "OriginalPrice":  67.91,
    "SalePrice":  41.98
}

Example

[ScriptBlock]$SendEmail = { 
    Param(
        $Book,
        $Msg
    )

    $Body = "<h1><a href=$($Book.URL)>Get it!</a></h1>"

    Send-MailMessage `
        -From "[email protected]" `
        -To "[email protected]" `
        -Subject $Msg `
        -Body $Body `
        -BodyAsHtml `
        -SmtpServer "mail.mydomain.com"

    Write-Host "Sending email!"
}

Update-KindleBookPrices -AlertScriptBlock $SendEmail
Checking price of Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell
Found discount for Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell, new price is $41.98 (original: $61.99)
Sending email!

pskindlewatch's People

Contributors

mdjx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pskindlewatch's Issues

Add-KindleBook : You cannot call a method on a null-valued expression.

I like the idea of this, but trying to use the module, I get the above error on PS 5 and PS 7.
Tried this with a book for one of my kids.

Add-KindleBook -BookURL "https://www.amazon.com/dp/B07TD6DZTC/"

Error:
Add-KindleBook : You cannot call a method on a null-valued expression.
At line:1 char:1

  • Add-KindleBook -BookURL "https://www.amazon.com/dp/B07TD6DZTC/"
  •   + CategoryInfo          : InvalidOperation: (:) [Add-KindleBook], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull,Add-KindleBook
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.