Skip to content

Instantly share code, notes, and snippets.

@jaboutboul
Created August 30, 2012 21:19
Show Gist options
  • Save jaboutboul/3541300 to your computer and use it in GitHub Desktop.
Save jaboutboul/3541300 to your computer and use it in GitHub Desktop.
kivikfinder-findproblems
#after problem is detected, find the problem
def findproblems(html,soup,br,user_id,number):
soup=BeautifulSoup(html, "lxml")
#searches for No location text
noavailable=soup.findAll("div", {"class": "sc_com_noLocationText sc_find_it_location_text"})
noavailablesize=len(noavailable)
noresults=soup.findAll("h2", {"class": "headerLeftNavi"}) #searches for "search results" -meaning invaild entry
nosize=len(noresults)
outofstock=soup.findAll("div", {"class": "sc_com_stockInfo sc_graph_stockInfo_container"}) #searches for out of stock text
outofstocksize=len(outofstock)
if(outofstocksize==1): #if item is out of stock
outofstock1=soup.find("div", {"class": "sc_com_stockInfo sc_graph_stockInfo_container"}).text
instock=outofstock1.rfind("This product is out of stock at your selected store.") #make sure out of stock
if(instock>0):
return sendOut("This item is currently out of stock",number)
if(nosize==1): #some type of error-- let's find it
noresults=noresults[0].text
if(noavailablesize==1):
noavailable=noavailable[0].text
#if no info is available
if(noavailable=="Contact staff for purchase and information"): #make sure no location
response= noavailableF(html,user_id) #although no location, find other info
return sendOut(response,number)
elif (noresults=="Search Results"): #make sure invaild entry
return sendOut("Invaild entry. Please send item numbers only",number)
#some item numbers have "confirm screens" -select the form with store number
br.select_form(name="stocksearch")
br.form['ikeaStoreNumber1']= [local_settings.STORE_NUMBER]
br.submit()
html=br.response().read()
response= pullInfo(html,br,user_id,number)
return sendOut(response,number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment