예제 #1
0
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
예제 #2
0
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)
예제 #3
0
def check_price():
    current_prices = {}
    
    url =  "http://www.kaixin001.com/!stall/!dialog/buygoodsfromsys.php"
    error_msg, url, redirected_url, html = download(url)

    page = WebPage(url, html)

    #print page.doc.items()

    ele = page.doc.findall('.//li')
    for e in ele:
        # goods name
        classes = e.find_class('name')
        name = classes[0].text_content()
        # goods id
        element = e.find(".//input")
        dic= {}
        for k,v in element.items():
            dic[k] = v
        gid = dic['value']
        # good price
        price = e.find_class('price')
        a = price[0].find('.//span')
        price =   a.text_content()
        #
        #print name, gid, price
        current_prices[str(gid).strip()] = int(price)
        #
    return current_prices
예제 #4
0
    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"
예제 #5
0
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
예제 #6
0
def get_stall_id():
    url =  "http://www.kaixin001.com/!stall/!dialog/buygoodsfromsys.php"
    error_msg, url, redirected_url, html = download(url)
    page = WebPage(url, html)

    #@@@@@@@@@@@@@ get stall id
    STALL_ID = None
    elements = page.doc.findall(".//input")
    for e in elements:
        dic = {}
        for k,v in e.items():
            dic[k] = v
        if dic['name'] == "stallid":
            #print dic
            STALL_ID = dic['value']
    return str(STALL_ID).strip()
예제 #7
0
def get_goods_onstall( goodsid, stallid, ):
    kxt = int( random.random() * 100000000.0)
    
    url = "http://www.kaixin001.com/!stall/!dialog/stallgoodsinfo.php?stallid="+str(stallid)+"&goodsid="+str(goodsid)+"&k_x_t=" + str(kxt)
    
    error_msg, url, redirected_url, html = download(url)
    page = WebPage(url, html)

    els = page.doc.find_class('numb')
    num = els[-1].text_content()
    if len(num) ==0:
        return 0
    else:
        return int( els[-1].text_content() )

    
    pass
예제 #8
0
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)