R
R
Roman Komyagin2020-08-11 23:50:19
Python
Roman Komyagin, 2020-08-11 23:50:19

How to get certain data from the .json() variable of the view?

Using the requests library, I received data from the site and enclosed it in a variable, attributed it to .json () to print it out, but from all the junk that I output, I only need certain data. Here is the code:

import requests
import config
TRN = config.TRN

ni = input('epic-nickname: ')

pl = input('platform: ')

response = requests.get(
  'https://api.fortnitetracker.com/v1/profile/' + pl + '/' + ni,
  headers= {'TRN-Api-Key':TRN}
  )
r = response.json()
print(r)


After entering pl and ni, a lot of data is displayed, especially unnecessary ones
Here is an example:

epic-nickname: BBG Bucke
platform: pc

{'accountId': '0f390cff-5a52-41b8-b8a6-667f8bfe8d65', 'avatar': ' https:// trackercdn.com/legacycdn/fortnite/CFB66844... ', 'platformId': 103, 'platformName': 'kbm', 'platformNameLong': 'KB/M', 'epicUserHandle': 'BBG Bucke', 'stats' : {'p2': {'trnRating': {'label': 'TRN Rating', 'field': 'TRNRating', 'category': 'Rating', 'valueInt': 1218, 'value': '1218' , 'rank': 1723936, 'percentile': 13.0, 'displayValue': '1,218'}, 'score': {'label':'Score', 'field':
'Score', 'category': 'General', 'valueInt': 526820, 'value': '526820', 'rank': 363463, 'percentile': 0.1, 'displayValue': '526,820'}, 'top1' : {'label': 'Wins', 'field': 'Top1', 'category': 'Tops', 'valueInt': 324, 'value': '324', 'rank': 92206, 'percentile': 0.1, 'displayValue': '324'}, 'top3': {'label': 'Top 3', 'field': 'Top3', 'category': 'Tops', 'valueInt': 0, 'value' : '0', 'rank': 1, 'displayValue': '0'}, 'top5': {'label': 'Top 5', 'field': 'Top5', 'category': 'Tops', 'valueInt': 0, 'value': '0', 'rank': 1, 'displayValue': '0'}, 'top6': {'label': 'Top 6', 'field': 'Top6', 'category': 'Tops ', 'valueInt':
Kills/Match', 'field': 'KPG', 'category': 'General', 'valueDec': 3.36, 'value': '3.36', 'rank': 1287801, 'percentile': 1.6, 'displayValue' : '3.36'}, 'avgTimePlayed': {'label': 'Avg. Match Time', 'field': 'AvgTimePlayed', 'category': 'General', 'valueDec': 390.14, 'value': '390.14', 'percentile': 0.5, 'displayValue': '6m 30s'}, 'scorePerMatch': {'label': 'Score/Match', 'field': 'ScorePerMatch', 'category': 'General', 'valueDec': 162.25, 'value': '162.25', 'rank': 10119506 , 'percentile': 29.0, 'displayValue': '162.25'}, 'scorePerMin':
1851, 'value': '1851', 'rank': 196339, 'percentile': 6.0, 'displayValue': '1,851'}, 'score': {'label': 'Score', 'field': 'Score ', 'category': 'General', 'valueInt': 433298, 'value': '433298', 'rank': 872526, 'percentile': 0.1, 'displayValue': '433,298'}, 'top1': { 'label': 'Wins'

How can I deduce from all this that ONLY 'accountId' is allowed? (at the beginning of this output)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2020-08-11
@BloomEe

r = response.json()
print(r['accountId'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question