Skip to content

Instantly share code, notes, and snippets.

@D-32
Last active March 23, 2017 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D-32/681253359cd4f1e6ae59df9f1d70e532 to your computer and use it in GitHub Desktop.
Save D-32/681253359cd4f1e6ae59df9f1d70e532 to your computer and use it in GitHub Desktop.
import requests
import json
import uuid
import time
from requests import Request, Session
# this is the initial call to get cookies and shit
s = Session()
r1 = s.get('https://challengethefuture.postfinance.ch/Contest/2')
totals = []
def q():
# here we prepare the SaveAnswer call. We do this before, as the time between the
# GetQuestion and SaveAnswer call has to be as short as possible
url = 'https://challengethefuture.postfinance.ch/Question/SaveAnswer'
req = Request('POST', url, data={'answerID':'0', 'questionGUID':'0'})
prepped = s.prepare_request(req)
id = ''
# posting the GetQuestion, after we get a response we want to be as fast as possible
r2 = s.post('https://challengethefuture.postfinance.ch/Question/GetQuestion', data={})
# json parsing is pretty fast, could be optimised though I guess
j = json.loads(r2.text)
qid = j['QuestionID']
guid = j['id']
# best if ever
if qid == 96:
id = '270'
elif qid == 91:
id = '255'
elif qid == 87:
id = '243'
elif qid == 95:
id = '267'
elif qid == 94:
id = '264'
elif qid == 90:
id = '252'
elif qid == 92:
id = '258'
elif qid == 88:
id = '246'
elif qid == 93:
id = '261'
elif qid == 89:
id = '249'
elif qid == 137:
id = '393'
else:
print("unknown id:")
print(qid)
# now let's update the prepared request with the actual data we need
prepped.body = 'answerID='+id+'&questionGUID='+guid
prepped.headers['Content-Length'] = len(prepped.body)
r = s.send(prepped)
# at this point the clock isn't ticking anymore
# we can now lose time by calling a new method
a(r.text.encode('utf-8'))
def a(text):
j = json.loads(text)
totals.append(j['pointsWon']) # < this is for calculating the avg
if j['lastQuestion']:
avg = reduce(lambda x, y: x + y, totals) / len(totals)
print(avg)
# we basically only want to submit our game if we're beating the highscore
# hopefully we won't need to go higher anymore, but who knows...
if avg > 219982.9:
print("Yay!")
f(uuid.uuid1())
else:
# time.sleep was an idea to get faster by having short breaks
# don't think it helped though
time.sleep(0.1)
q()
def f(id):
# here we submit our result, the response gives back an error, but it still gets added to the highscore
r = requests.post('https://challengethefuture.postfinance.ch/results', data={'ShareGuid':id, 'Nickname':'D-32', 'Firstname':'Dylan', 'Surname':'Marriott', 'Email':'info@d-32.com', 'Cometition':True, 'TermsAccepted':True}, cookies=r1.cookies)
print(r.text)
q()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment