/serveradmindowntime

ServerAdmin Downtime - rockin' ASCII art, retail API CLI browser for BASH.

Primary LanguageShellGNU General Public License v3.0GPL-3.0

ServerAdmin Downtime
--------------------

ServerAdmin Downtime is a command-line web services browser. It is my tongue-in-cheek entry for Recommerce Hack Day (http://www.recommerceday.com) on Sept. 17, 2011. It allows one to search various APIs, and browse ASCII art versions of their catalog. It has a simple, driver interface, allowing you to add any searchable JSON-returning web server API. It was fun to participate with the Zappos team, and Sierra Trading Post, whos APIs are currently implemented.

Use a BLACK BACKGROUND for best results!

INSTALL
-------

I have successfully tested this on a bare Debian Squeeze with the following additional packages:

apt-get install imagemagick html2text spidermonkey-bin

NOTE: spidermonkey-bin has been dropped from Ubuntu 11.04 Natty, so I compiled from source for the competition. 

ADD DRIVERS
-----------

1. copy an existing driver:
   cp /appinstall/location/drivers/Sierra_Trading_Post.sh /appinstall/location/drivers/Zappos.sh
2. create a matching images folder to hold your related images
   mkdir /appinstall/location/images/Zappos
3. copy your favorite homepage image into the new folder, (NOTE: I found that large letters at about 1200xsomething worked nicely)
   cp mylogo.jpg /appinstall/location/images/Zappos
4. copy your favorite error photo into the same folder
   cp myerror.jpg /appinstall/location/images/Zappos
5. open your driver file in your favorite editor
   emacs /appinstall/location/drivers/Zappos.sh
5a. modify your driver variables:

DRIVERNAME="Sierra_Trading_Post"
HOMEPAGEPIC="sierra2.jpg"
APIURL="http://apps.sierratradingpost.com/api/1.0/products/search"
SIERRAAPIKEY="MYAPIKEY"
    
    to:

DRIVERNAME="Zappos"
HOMEPAGEPIC="zappos.jpg"
APIURL="http://api.zappos.com/Search"
APIPRODUCTURL="http://api.zappos.com/Product/id/"
ZAPPOSAPIKEY="MYAPIKEY"

5b. change setitemvariables() to reflect the JSON for your API

setitemvariables()
{
    ITEMID=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Id")
    ITEMNAME=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Name")
    ITEMURL=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Url")
    ITEMWEBURL=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].WebUrl")

    # REVIEWS
    ITEMREVIEWSURL=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Reviews.ReviewsUrl")
    ITEMREVIEWSCOUNT=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Reviews.ReviewCount")
    ITEMREVIEWSAVERAGERATING=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Reviews.AverageRating")

    # SIZES
    ITEMSIZES=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].SizesAvailable.SIZE")

    # IMAGE
    ITEMIMAGEMEDIUM=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Images.PrimaryMedium")
    ITEMIMAGESMALL=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].Images.PrimarySmall")
    
    #DESCRIPTION
    ITEMDESCRIPTIONHTMLSIMPLE=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].DescriptionHtmlSimple")

    # PRICING
    ITEMLISTPRICE=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].ListPrice")
    ITEMFINALPRICE=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Result[${ITER}].FinalPrice")
}

to:

setitemvariables()
{
    ITEMSTATUSCODE=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.statusCode")

    ITEMSTYLEID=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].styleId")
    ITEMPRICE=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].price")
    ITEMORIGINALPRICE=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].originalPrice")
    ITEMPRODUCTURL=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].productUrl")
    ITEMCOLORID=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].colorId")
    ITEMPRODUCTNAME=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].productName")
    ITEMBRANDNAME=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].brandName")
    ITEMTHUMBNAILIMAGEURL=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].thumbnailImageUrl")
    ITEMPERCENTOFF=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].percentOff")
    ITEMPRODUCTID=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.results[${ITER}].productId")

    ITEMTERM=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.term")
    ITEMCURRENTRESULTCOUNT=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.currentResultCount")
    ITEMTOTALRESULTCOUNT=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.totalResultCount")
}

6c. unset those variables in unsetitemvariables():

unsetitemvariables()
{
    unset ITEMID
    unset ITEMNAME
    unset ITEMURL
    unset ITEMWEBURL

    # REVIEWS
    unset ITEMREVIEWSURL
    unset ITEMREVIEWSCOUNT
    unset ITEMREVIEWSAVERAGERATING

    # SIZES
    unset ITEMSIZES

    # IMAGE
    unset ITEMIMAGE
    
    #DESCRIPTION
    unset ITEMDESCRIPTIONHTMLSIMPLE

    # PRICING
    unset ITEMLISTPRICE
    unset ITEMFINALPRICE
} 

to:

unsetitemvariables()
{
    unset ITEMSTATUSCODE

    unset ITEMSTYLEID
    unset ITEMPRICE
    unset ITEMORIGINALPRICE
    unset ITEMPRODUCTURL
    unset ITEMCOLORID
    unset ITEMPRODUCTNAME
    unset ITEMBRANDNAME
    unset ITEMTHUMBNAILIMAGEURL
    unset ITEMPERCENTOFF
    unset ITEMPRODUCTID

    unset ITEMTERM
    unset ITEMCURRENTRESULTCOUNT
    unset ITEMTOTALRESULTCOUNT
}

6d. do the same with setsearchresultcount()

setsearchresultcount()
{
    RESULTCOUNT=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.Count")
}

to:

setsearchresultcount()
{
    RESULTCOUNT=$(echo ${SEARCHJSON} | ${JSAWKME} "return this.totalResultCount")
}

6e. etc. etc. etc. You get the 'picture'...

THANKS
------

- Crystal Chang, the boss of the Zappos API team, for contacting me and inviting me out to the competition. (Thank you!)
- The rest of the Zappos API team, and developers, who made me feel welcome and kept me safe on Fremont St. (That's you, Will!)
- Mike Tran from Sierra Trading Post (http://www.sierratradingpost.com) hanging out and supporting my wild ideas! (I still think there is something to that concierge idea of yours!)
- Micha Niskin, creator of jsawk, without which I would still be figuring out a way to parse my JSON with BASH. (https://github.com/micha)
- For everything!