Browse Source

Cache dota2 api requests

master
Brandon Cornejo 8 years ago
parent
commit
1ae9be6a79
  1. 3
      app/templates/profile.html
  2. 2
      app/templates/teamspeak.html
  3. 3
      app/utils.py
  4. 2
      app/views.py

3
app/templates/profile.html

@ -103,7 +103,8 @@
{% endblock %}
{% block pagescripts %}
<script src="http://code.highcharts.com/highcharts.js"></script>
{#<script src="http://code.highcharts.com/highcharts.js"></script>#}
<script src="//cdnjs.cloudflare.com/ajax/libs/highcharts/4.0.3/highcharts.js"></script>
<script>
$('#winrate_modal').on({
'uk.modal.show': function(){

2
app/templates/teamspeak.html

@ -36,12 +36,12 @@
{% endblock %}
{% block pagescripts %}
{% set teamspeak_data = get_teamspeak_window() %}
<script src="//cdnjs.cloudflare.com/ajax/libs/highcharts/3.0.7/highcharts.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/highcharts/3.0.7/modules/map.src.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/highcharts/3.0.7/modules/data.src.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/world-map-shapes.js') }}"></script>
{% cache 60*5 %}
{% set teamspeak_data = get_teamspeak_window() %}
<script>
$(document).ready(function() {
$('#unique_clients').html("{{ ts3_active_clients(teamspeak_data) }}");

3
app/utils.py

@ -18,6 +18,7 @@ def get_steam_userinfo(steam_id):
data = requests.get('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0001/', params=options).json()
return data['response']['players']['player'][0] or {}
@cache.cached(timeout=60*60*24, key_prefix='hero_data')
def get_api_hero_data():
data = requests.get("https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?key="+app.config['DOTA2_API_KEY']+"&language=en_us").json()
return data
@ -32,6 +33,7 @@ def complete_hero_data(key, value):
def get_hero_data_by_id(hero_id):
return API_DATA['result']['heroes'][hero_id-1]
@cache.cached(timeout=60*60*24, key_prefix='tavern_data')
def parse_valve_heropedia():
data = requests.get('http://www.dota2.com/heroes/')
soup = BeautifulSoup(data.text)
@ -83,6 +85,7 @@ def utility_processor():
def ts3_current_clients():
num = create_teamspeak_viewer()[1]
return num
@cache.memoize(60*5)
def get_teamspeak_window():
data_list = getTeamspeakWindow()
return data_list

2
app/views.py

@ -3,7 +3,7 @@ from flask import render_template, flash, redirect, g, request, url_for, session
from datetime import datetime
from functools import wraps
from app import app, db, oid, cache
from app import app, db, oid
from models import User, Event
from utils import get_steam_userinfo
from board import registerUserForumId

Loading…
Cancel
Save