Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kol.Session import Session
- from kol.request.ChoiceRequest import ChoiceRequest as CR
- from kol.request.UseItemRequest import UseItemRequest as UR
- import re
- username = ""
- password = ""
- include_action_data = True
- number_reg = re.compile("(?<=the box clearly says ")\d+")
- choice_reg = re.compile("(?<=submit value=\")[^\"]+")
- face_reg = re.compile("(?<=the )\w+(?= face)")
- deepest=-1
- deepest_full=-1
- choice=-1
- nonBuzz = []
- myData= []
- myChoices = []
- def sixbuzz():
- lastRow = myData[deepest-1]
- return len(lastRow)==6 and len(list(set(lastRow)))==1 and "Z" in lastRow
- def parse_response(body):
- datapoint = None
- if "the box clearly says" in body:
- datapoint = number_reg.search(body).group()
- elif "hear a quiet" in body:
- datapoint = "C"
- elif "the box makes a loud" in body:
- datapoint = "B"
- elif "box makes a harsh buzzing noise" in body:
- datapoint = "Z"
- if datapoint is None:
- f = open("dump.html","w")
- f.write(body)
- f.close()
- raise Exception("Unknown response, dumped to file dump.html")
- return datapoint
- def parse_actions(body):
- myList = []
- actions = [x.lower() for x in choice_reg.findall(body)[:6]]
- for act in actions:
- if "push" in act:
- current = "push_"
- elif "counter" in act:
- current = "ccw_"
- else:
- current = "cw_"
- myList.append(current+face_reg.search(act).group())
- myChoices.append(myList)
- def reset():
- print("Resetting box")
- make_choice=CR(s,525,7)
- try:
- make_choice.doRequest()
- except:
- pass
- use_box = UR(s,5054)
- use_box.doRequest()
- while True:
- make_choice=CR(s,525,1)
- make_choice.doRequest()
- if parse_response(make_choice.responseText)=="Z":
- break
- print("Box reset")
- def write_file():
- f=open("datafile.csv","w")
- for line1,line2 in zip(myChoices,myData):
- if include_action_data:
- f.write(",".join(line1)+"\n")
- f.write(",".join(line2)+"\n")
- f.close()
- s = Session()
- s.login(username,password)
- print "Logged in!"
- reset()
- while True:
- print "Starting new choice with deepest "+`deepest`+" and deepest_full "+`deepest_full`
- i=0
- while True:
- if i>deepest:
- myData.append([])
- nonBuzz.append(None)
- deepest=i
- if i<=deepest_full:
- make_choice=CR(s,525,nonBuzz[i])
- make_choice.doRequest()
- else:
- choice = len(myData[i])+1
- make_choice=CR(s,525,choice)
- make_choice.doRequest()
- result = parse_response(make_choice.responseText)
- print "Took choice "+`choice`+" at "+`i`+" and got "+result
- if not len(myData[i]):
- parse_actions(make_choice.responseText)
- myData[i].append(result)
- if len(myData[i])==6:
- deepest_full=i
- if result == "Z":
- break
- elif nonBuzz[i] is None:
- nonBuzz[i]=choice
- i+=1
- write_file()
- print("File written")
- if sixbuzz():
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement