-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
169 lines (129 loc) · 6.18 KB
/
Copy pathREADME
File metadata and controls
169 lines (129 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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!