Dies ist eine weitere ähnliche Frage, die anscheinend in der Nähe kommt:
Zugriff auf Werte aus Python Sub-Dictionary
Wenn ich versuche, Titel = [Benutzer zu addieren) [usw.] für Benutzer in Daten. Ganzzahlen
Ich kann mit Sicherheit versuchen, eine für Schleife hinzuzufügen, aber ich frage mich, ob das überkill ist oder nicht.
Code: Select all
print(f"{user} is streaming {data.get('title')}")
Mein Python -Code
Code: Select all
#-
# Check status against JSON file
# This also set the keys on a per-user basis
#
def processJSON():
with open('channel_data.json', 'r') as file:
lines = file.readlines()
channel_json = json.loads("".join(lines))
data = {}
for element in channel_json['data']:
data[element['user_login']] = element
#-
# Determine if the user is online or not
for user in streamers:
if user in data.keys():
print(f"{user} is streaming {data.get('title')}")
else:
print(f"{user} is offline :(")
# print( json.dumps(data, indent=3) )
# End processJSON()
processJSON()
Code: Select all
{
"dutchf0x": {
"user_login": "dutchf0x",
"user_name": "DuctchF0x",
"game_name": "Monopoly Plus",
"title": "nobody loses friendships with this game",
"viewer_count": 24773,
"started_at": "2021-07-07T16:59:08Z",
"thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_philza-{width}x{height}.jpg",
"is_mature": false
},
"libertyranger": {
"user_login": "libertyranger",
"user_name": "libertyranger",
"game_name": "Science \\u0026 Technology",
"title": "Streaming UFO Cam - Background Audio is Copyright FREE, 1920s through 1960s Sci-Fi Radio Theater",
"viewer_count": 1,
"started_at": "2021-07-06T12:52:25Z",
"thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_libertyranger-{width}x{height}.jpg",
"is_mature": false
}
}