Working with the Pocket API dataset and trying to parse out details about each item. Unfortunately, I am stuck at looking at "list" data and not the individual details for each item.
JSON
"status": 1,
"complete": 1,
"list": {
"2872254473": {
"item_id": "2872254473",
"resolved_id": "2872254473",
"given_url": "https://i.redd.it/g0iq3upzffe41.jpg",
"given_title": "i.redd.it",
"favorite": "0",
"status": "1",
"time_added": "1580666841",
"time_updated": "1580667500",
"time_read": "1580667500",
"time_favorited": "0",
"sort_id": 0,
"resolved_title": "",
"resolved_url": "https://i.redd.it/g0iq3upzffe41.jpg",
"excerpt": "",
"is_article": "0",
"is_index": "0",
"has_video": "0",
"has_image": "2",
"word_count": "0",
"lang": "",
"domain_metadata": {
"name": "Reddit",
"logo": "https://logo.clearbit.com/reddit.com?size=800",
"greyscale_logo": "https://logo.clearbit.com/reddit.com?size=800&greyscale=true"
},
Python Code
import json
with open('2. JSON Data (Pocket Articles Tagged TIL)2.json') as f:
data = json.load(f)
print(data)
print('----')
print(type(data))
print(type(data['list']))
for item in data['list']:
print(item)
The issue is I can't seem to use data['item'] or data['list']['item']. I am trying to query the added_date and item_id for each individual item.
CodePudding user response:
You can use following code to get each items id and time_added:
for list_key, value in data['list'].items():
print(list_key, value['item_id'], value['time_added'])