In [1]:
from npoapi import Media
import ijson
from datetime import datetime
import sys
client = Media(env="test").configured_login()
Receive (streamingly) the latest 100000 changes.
In [2]:
objects = ijson.items(client.changes(stream=True, limit=100000), 'changes.item')
data = {}
Now iterate those changes and collect all sort dates per broadcaster (this may take some time)
In [3]:
count = 0
print("Iterating all results, and collecting some data")
for o in objects:
if count % 20000 == 0:
sys.stdout.write("\n%05d" % count)
if count % 1000 == 0:
sys.stdout.write('.')
sys.stdout.flush()
count += 1
if "media" in o:
media = o["media"]
for broadcaster in media["broadcasters"]:
if "sortDate" in media:
sortDate = datetime.fromtimestamp(media["sortDate"] / 1e3)
bid = broadcaster["id"]
if not bid in data:
data[bid] = []
data[bid].append(sortDate)
Now collect some information about the collected results and show it
In [4]:
sorted_by_value = sorted(data.items(), key=lambda kv: -1 * len(kv[1]))
for e in sorted_by_value:
print("%-20s %d" % (e[0], len(e[1])))
In [ ]:
In [ ]: