Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
map.txt

api_key.py
Binary file added __pycache__/api_key.cpython-36.pyc
Binary file not shown.
54 changes: 54 additions & 0 deletions adv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import random
import requests
import json
from api_key import API_KEY

url = 'https://lambda-treasure-hunt.herokuapp.com/api'

headers = {
'Authorization': API_KEY
}

def init():
r = requests.get(f'{url}/adv/init/', headers=headers)
print(r.json())


def move():
payload = {"direction":"s"}
r_move = requests.post(f'{url}/adv/move', data=json.dumps(payload), headers=headers)
save = r_move.json()
data = {
'room_id': save['room_id'],
'coordinates': save['coordinates'],
'exits': save['exits'],
}
current_state = get_contents()
current_state[save['room_id']] = data

save_content(current_state)
print(save)

def save_content(data):
with open('map.txt', 'w') as f:
f.write(json.dumps(data, indent=4))


def get_contents():
map_file = open('map.txt', 'rb').read()
contents = json.loads(map_file)
return contents



# init()
move()