Hi guys,

I want to get the correct data if if key == false from a json data. My if
else condition seems to be working however the data is inconsistent. Here's
my code:


class DotaMatches(TemplateView):
    template_name = 'matches/dota_matches.html'

    def get(self, request, *args, **kwargs):
        # Get the URL of the API using requests module
        url = requests.get('https://api.opendota.com/api/proMatches')
        # Decode the data
        json_data = url.json()

        # List that will contain dictionaries
        game_data = []

        for data in json_data:
            # Will contain the values from the dictionary data of json_data
            j_data = {}
            j_data['League'] = data['league_name']
            j_data['Radiant'] = data['radiant_name']
            j_data['Dire'] = data['dire_name']
            j_data['Duration'] = str(timedelta(seconds=data['duration']))
            j_data['Finished'] = timeago.format(datetime.now() -
datetime.fromtimestamp(data['start_time']))

            # Check who the winner of the match
            if data['radiant_win'] == 'False':
                j_data['Winner'] = data['dire_name']
            else:
                j_data['Winner'] = data['radiant_name']

            # Put the data in our game_data list
            game_data.append(j_data)

        return render(request, self.template_name, {'game_data': game_data})


Not sure if there's something that I need to do first before running the if
- else condition.



Regards,
Jarvis

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLfU_EsWf4AmNMHcraBkdqQgKSmPsBoMzfFfjfxu%2BYZZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to