tunic-tracker-redux/tunictracker/tracker/views.py

43 lines
1.6 KiB
Python
Raw Normal View History

from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from json import loads
from math import floor
import requests
# Create your views here.
def index(request):
tracker_output = loads(requests.get('http://localhost:8000/spoiler').text)
# with open('structure_final_final_v10.json', 'r') as t:
# tracker_output = loads(t.read())
tracker_debug = tracker_output["Debug"]
tracker_totals = tracker_output["Totals"]
tracker_current_scene = tracker_output["Scene"]
tracker_current_scene_data = tracker_output["Scenes"][tracker_current_scene]
template = loader.get_template("tracker/index.html")
temp_tracker_checks = tracker_current_scene_data["Checks"]
for i, check in enumerate(temp_tracker_checks.keys()):
temp_data = {
"Check": temp_tracker_checks[check],
"CheckNum": floor(int(i)%3)
}
temp_tracker_checks[check] = temp_data
tracker_current_scene_data["Checks"] = temp_tracker_checks
temp_tracker_entrances = tracker_current_scene_data["Entrances"]
for i, entrance in enumerate(temp_tracker_entrances.keys()):
temp_data = {
"Entrance": temp_tracker_entrances[entrance],
"EntranceNum": floor(int(i)%3)
}
temp_tracker_entrances[entrance] = temp_data
tracker_current_scene_data["Entrances"] = temp_tracker_entrances
context = {
"debug": tracker_debug,
"totals": tracker_totals,
"scene": tracker_current_scene,
"scene_data": tracker_current_scene_data
}
return HttpResponse(template.render(context, request))