Furthere tweaks to newegg

This commit is contained in:
Luke Rogers 2013-11-29 20:40:18 +13:00
parent 49bb446c27
commit 8d7f853426

View file

@ -1,12 +1,12 @@
from util import hook, http, text, web from util import hook, http, text, web
import json import json
ITEM_URL = "http://www.newegg.com/Product/Product.aspx?Item={}" ITEM_URL = "http://www.newegg.com/Product/Product.aspx?Item={}"
@hook.command @hook.command
def newegg(inp): def newegg(inp):
""" newegg <item name> -- Searches newegg.com for <item name> """ """newegg <item name> -- Searches newegg.com for <item name>"""
request = { request = {
"PageNumber": 1, "PageNumber": 1,
@ -29,17 +29,18 @@ def newegg(inp):
item = r["ProductListItems"][0] item = r["ProductListItems"][0]
data = { title = text.truncate_str(item["Title"], 50)
'title': text.truncate_str(item["Title"], 50),
'rating': item["ReviewSummary"]["Rating"], if not item["ReviewSummary"]["TotalReviews"] == "[]":
'ratingcount': item["ReviewSummary"]["TotalReviews"][1:-1] rating = "Rated {}/5 ({} ratings)".format(item["ReviewSummary"]["Rating"],
} item["ReviewSummary"]["TotalReviews"][1:-1])
print item else:
rating = "No Ratings"
if not item["FinalPrice"] == item["OriginalPrice"]: if not item["FinalPrice"] == item["OriginalPrice"]:
data['price'] = "{FinalPrice}, was {OriginalPrice}".format(**item) price = "{FinalPrice}, was {OriginalPrice}".format(**item)
else: else:
data['price'] = item["FinalPrice"] price = item["FinalPrice"]
tags = [] tags = []
@ -54,8 +55,12 @@ def newegg(inp):
if item["IsFeaturedItem"]: if item["IsFeaturedItem"]:
tags.append("\x02Featured\x02") tags.append("\x02Featured\x02")
data["tags"] = ", ".join(tags) if item["IsShellShockerItem"]:
tags.append("\x02SHELL SHOCKER®\x02")
data["url"] = web.try_isgd(ITEM_URL.format(item["NeweggItemNumber"])) tag_text = u", ".join(tags)
return "\x02{title}\x02 ({price}) - Rated {rating}/5 ({ratingcount} ratings) - {tags} - {url}".format(**data) url = web.try_isgd(ITEM_URL.format(item["NeweggItemNumber"]))
return u"\x02{}\x02 ({}) - {} - {} - {}".format(title, price, rating,
tag_text, url)