Code Monkey home page Code Monkey logo

pskindlewatch's Introduction

PSKindleWatch

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

Installation

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 3 cmdlets

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Add-KindleBook                                     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/"

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 either on a loop in a PowerShell window, or as a scheduled task.

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), and a descriptive message (see example above in green).

{
    "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

Watchers

James Cloos avatar

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.