def sell(goodsid, num): url = "http://www.kaixin001.com/!stall/!dialog/salestoregoods.php" error_msg, url, redirected_url, html = download(url) #print error_msg, url, redirected_url, len(html) page = WebPage(url, html) # find buy num try: ele = page.doc.get_element_by_id('saleGoods'+goodsid) except: return False ele2 = ele.find_class("c9 ffc tac") raw = ele2[0].text_content() want = re.search(re.compile('[0-9]+'),raw) wants = want.group(0) if int(wants) == 0: return False # prepare request data url, data = page.get_form(0) ndata = {} ndata['stallid'] = data['stallid'] ndata['goodsid'] = goodsid if int(num) > int(wants): ndata['num'] = str(wants) else: ndata['num'] = str(num) #submit sell request error_msg, url, redirected_url, html = download(url, ndata) #print "start selling....", time.ctime() return True
def set_price(stall_id, goods_id, low_per, high_per): url = 'http://www.kaixin001.com/!stall/!dialog/changeprice.php?stallid='+stall_id+'&goodsid='+goods_id error_msg, url, redirected_url, html = download(url) page = WebPage(url, html) es = page.doc.find_class("nomargin") e = es[0].find(".//span") price = e.text_content() if len(price.strip()) == 0: return False purchase_price = float(price.strip()) url, data = page.get_form(0) dic = {} for k,v in data.items(): dic[k] = v dic['dealsetting'] = '1' lprice = int(purchase_price* (1.0 + low_per)) lprice = price_ajust(lprice) dic['minprice'] = str(lprice) hprice = int(purchase_price* (1.0 + high_per)) hprice = price_ajust(hprice) dic['idealprice'] = str(hprice) dic['higglenum'] = "5" #print url, data.items() error_msg, url, redirected_url, html = download(url,dic)
def buy(goods_id, num): url = "http://www.kaixin001.com/!stall/!dialog/buygoodsfromsys.php" error_msg, url, redirected_url, html = download(url) page = WebPage(url, html) ###################################### # select goods try: url, data = page.get_form(0) data['goodsid'] = str(goods_id).strip() error_msg, url, redirected_url, html = download(url,data) except: return False ###################################3 # set num and buy try: page2 = WebPage(url, html) url, data = page2.get_form(0) except: return False # excessed the maxmum purchase per hour dic ={} for k,v in data.items(): dic[k] =v dic['num'] = str(num) error_msg, url, redirected_url, html = download(url,dic)
def login(self, user, pwd): error_msg, url, redirected_url, html = download( self.URL_KAIXIN_HOME ) page = WebPage(url, html) action, fields = page.get_form(0) fields['email'] = user fields['password'] = pwd fields['remember'] = 0 error_msg, url, redirected_url, html = download( self.URL_KAIXIN_LOGIN , fields ) #print error_msg, url, redirected_url, len(html) if redirected_url == False: return False if redirected_url.count('?uid=') > 0: print "LOGGED IN KAIXIN" else: return "NOT LOGIN"
def login(user, pwd): url = "http://kaixin001.com/" error_msg, url, redirected_url, html = download(url) page = WebPage(url, html) action, fields = page.get_form(0) fields['email'] = user fields['password'] = pwd fields['remember'] = 0 url = 'http://www.kaixin001.com/login/login.php' error_msg, url, redirected_url, html = download(url , fields) #print error_msg, url, redirected_url, len(html) if redirected_url == False: return False if redirected_url.count('?uid=') > 0: return True else: return False