Esempio n. 1
0
 def search(keyword):
   #items=db.GqlQuery("SELECT * FROM KeyContent")
   #for item in items.fetch(100):
   #  item.delete()
   utf8_keyword = keyword.encode('utf-8')
   item = db.GqlQuery("SELECT * FROM KeyContent WHERE keyword=:1", keyword.lower()).get()
   if item:
     result = item.content
   else:
     search_result = taobao.get(method = 'taobao.taobaoke.items.get', \
                                fields = 'iid,click_url,title,price', \
                                keyword = utf8_keyword, \
                                nick = TOP_TAOBAOKE_NICK, \
                                guarantee = 'true', \
                                sort = 'credit_desc', \
                                page_no = '1', \
                                page_size = '10')
     search_results = search_result["taobaoke_items_get_response"]["taobaoke_items"]["taobaoke_item"]
     search_results = sorted(search_results, key=lambda i: float(i["price"]))
     result = Taoggle._parse_search_result(search_results)
     list_result = taobao.get(method='taobao.taobaoke.listurl.get', q=keyword, nick=TOP_TAOBAOKE_NICK, outer_code='tg')
     list_url = list_result["taobaoke_listurl_get_response"]["taobaoke_item"]["keyword_click_url"]
     result += SEARCH_MORE_TEAMPLE % (utf8_keyword, googl.shortening(list_url),)
     item = KeyContent(keyword = keyword.lower(), content = result.decode('utf-8'))
     item.put()
   return result
Esempio n. 2
0
 def _parse_search_result(dataList):
   l = []
   counter = 0
   for i in dataList:
     counter += 1
     gurl = db.GqlQuery("SELECT * FROM GooURL WHERE item_id=:1", i["iid"]).get()
     if gurl:
       shorted_url = gurl.url
     else:
       shorted_url = googl.shortening(i["click_url"])
       gurl = GooURL(item_id=i["iid"], url=shorted_url)
       gurl.put()
     e = TAOBAOKE_ITEM_TEMPLATE % (counter, Taoggle._format_title(i["title"]), i["price"], shorted_url.encode('utf-8'),)
     l.append(e)
   return "".join(l)
Esempio n. 3
0
def main():
  url = "http://search8.taobao.com/browse/search_auction.htm?q=iPhone&pid=mm_14283632_0_0&search_type=auction&commend=all&at_topsearch=1&unid=12008982tg"  
  print googl.shortening(url)