comments!
This commit is contained in:
parent
8d7f853426
commit
9c7e2074f5
1 changed files with 6 additions and 0 deletions
|
@ -8,6 +8,7 @@ ITEM_URL = "http://www.newegg.com/Product/Product.aspx?Item={}"
|
||||||
def newegg(inp):
|
def newegg(inp):
|
||||||
"""newegg <item name> -- Searches newegg.com for <item name>"""
|
"""newegg <item name> -- Searches newegg.com for <item name>"""
|
||||||
|
|
||||||
|
# form the search request
|
||||||
request = {
|
request = {
|
||||||
"PageNumber": 1,
|
"PageNumber": 1,
|
||||||
"BrandId": -1,
|
"BrandId": -1,
|
||||||
|
@ -22,15 +23,18 @@ def newegg(inp):
|
||||||
"IsUPCCodeSearch": False
|
"IsUPCCodeSearch": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# submit the search request
|
||||||
r = http.get_json(
|
r = http.get_json(
|
||||||
'http://www.ows.newegg.com/Search.egg/Advanced',
|
'http://www.ows.newegg.com/Search.egg/Advanced',
|
||||||
post_data = json.dumps(request)
|
post_data = json.dumps(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# get the first result
|
||||||
item = r["ProductListItems"][0]
|
item = r["ProductListItems"][0]
|
||||||
|
|
||||||
title = text.truncate_str(item["Title"], 50)
|
title = text.truncate_str(item["Title"], 50)
|
||||||
|
|
||||||
|
# format the rating nicely if it exists
|
||||||
if not item["ReviewSummary"]["TotalReviews"] == "[]":
|
if not item["ReviewSummary"]["TotalReviews"] == "[]":
|
||||||
rating = "Rated {}/5 ({} ratings)".format(item["ReviewSummary"]["Rating"],
|
rating = "Rated {}/5 ({} ratings)".format(item["ReviewSummary"]["Rating"],
|
||||||
item["ReviewSummary"]["TotalReviews"][1:-1])
|
item["ReviewSummary"]["TotalReviews"][1:-1])
|
||||||
|
@ -58,8 +62,10 @@ def newegg(inp):
|
||||||
if item["IsShellShockerItem"]:
|
if item["IsShellShockerItem"]:
|
||||||
tags.append("\x02SHELL SHOCKER®\x02")
|
tags.append("\x02SHELL SHOCKER®\x02")
|
||||||
|
|
||||||
|
# join all the tags together in a comma seperated string ("tag1, tag2, tag3")
|
||||||
tag_text = u", ".join(tags)
|
tag_text = u", ".join(tags)
|
||||||
|
|
||||||
|
# create the item URL and shorten it
|
||||||
url = web.try_isgd(ITEM_URL.format(item["NeweggItemNumber"]))
|
url = web.try_isgd(ITEM_URL.format(item["NeweggItemNumber"]))
|
||||||
|
|
||||||
return u"\x02{}\x02 ({}) - {} - {} - {}".format(title, price, rating,
|
return u"\x02{}\x02 ({}) - {} - {} - {}".format(title, price, rating,
|
||||||
|
|
Reference in a new issue