-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfta.py
More file actions
41 lines (30 loc) · 1.11 KB
/
fta.py
File metadata and controls
41 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import json
from urllib import urlencode, urlopen
# Insert your specific values
SERVER = "https://codingquest.herokuapp.com"
PLAYER_ID = "1234567"
def get_questions(category):
"""Fetch questions from server"""
response = urlopen(SERVER + '/game?' + urlencode({'category': category, 'playerid': PLAYER_ID}))
if 200 <= response.getcode() <= 299:
return json.load(response)
else:
raise Exception('Error #%d: %r' % (response.getcode(), response.read()))
def post_answers(answers):
"""Post answers to server"""
response = urlopen(SERVER + '/game', json.dumps({"playerId": PLAYER_ID, "answers": answers}))
if 200 <= response.getcode() <= 299:
return json.load(response)
else:
raise Exception('Error #%d: %r' % (response.getcode(), response.read()))
def solve_echo(question):
return question
def main():
questions = get_questions('Echo')
print 'Questions:', questions
answers = [solve_echo(q) for q in questions]
print 'Answers: ', answers
result = post_answers(answers)
print 'Result: ', result
if __name__ == '__main__':
main()