Skip to content

Instantly share code, notes, and snippets.

@fangeugene
Created March 13, 2017 18:39
Show Gist options
  • Save fangeugene/0581ceec1eb88f629b13f5d3f1700bd8 to your computer and use it in GitHub Desktop.
Save fangeugene/0581ceec1eb88f629b13f5d3f1700bd8 to your computer and use it in GitHub Desktop.
Count Top Team Subscriptions
from models.subscription import Subscription
from collections import defaultdict
counts = defaultdict(int)
for s in Subscription.query(Subscription.model_type==1).fetch():
counts[s.model_key] += 1
sorted_counts = sorted(counts.items(), key=lambda x: -x[1])
for team, count in sorted_counts[:100]:
print team, count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment