I’ve been trying for a while, but I’m not very good with jinja2 templates, and I’m not sure how to pull the data I want from this json.
edited for brevity
{
"events": [{
"name": "Green Bay Packers at New Orleans Saints",
"shortName": "GB @ NO",
"competitions": [{
"competitors": [{
"homeAway": "home",
"team": {
"name": "Saints",
"abbreviation": "NO",
"displayName": "New Orleans Saints"
},
"score": "0"
},
{
"homeAway": "away",
"team": {
"name": "Packers",
"abbreviation": "GB",
"displayName": "Green Bay Packers"
},
"score": "0"
}
],
"status": {
"clock": 0.0,
"displayClock": "0:00",
"period": 0,
"type": {
"state": "pre",
"completed": false
}
}
}]
}]
}
I’d like to have a sensor for GB score, and I’m having some trouble in a couple of areas. The first issue is just matching abbreviation == GB
. In the dev tools template editor, I’m trying the following
{% for competitions in value_json.events %}
{% if competitors.team.abbreviation == 'GB' %}
"It's GB"
{% endif %}
{% endfor %}
But that results in an error UndefinedError: 'competitors' is undefined
Secondly, even if I was able to match the team abbreviation, I can’t think of a good way to pull the score value since it resides outside of the team tag.
For reference, this is using the ESPN NFL API. I used to use the NFL API with the following template, and I’m trying to recreate it using the ESPN API.
{% for game in value_json.gms %}
{% if game.h == 'GB' or game.v == 'GB' %}
{% if game.q != 'F' and game.q != 'P' and game.q != 'FO' and game.q != 'S' %}
{% if game.h == 'GB' %}
{{ game.hs }}
{% else %}
{{ game.vs }}
{% endif %}
{% else %}
0
{% endif %}
{% endif %}
{% endfor %}
Any help is hugely appreciated. Thanks in advance.