Skip to content

Instantly share code, notes, and snippets.

@blainegarrett
Last active June 11, 2018 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blainegarrett/4c7f5d6da7522088df3339d86c94f55c to your computer and use it in GitHub Desktop.
Save blainegarrett/4c7f5d6da7522088df3339d86c94f55c to your computer and use it in GitHub Desktop.
Calculate # of events created per month
# In the ./app dir execute: remote_api_shell.py -s arts-612.appspot.com
# Script to get all the events listed by when they were posted
from app.modules.events.internal.entities import EventEntity
q = EventEntity.query()
hist = {}
cursor = None
more = True
while(more):
entities, cursor, more = q.fetch_page(500, start_cursor=cursor)
for e in entities:
if not e.created_date: continue
key = "%s-%s" % (e.created_date.year, e.created_date.month)
hist[key] = hist.get(key, 0) + 1
print key
print hist
print len(hist.keys())
hist = {'2015-11': 44, '2015-10': 48, '2015-12': 33, '2016-3': 32, '2017-12': 37, '2017-11': 55, '2017-10': 54, '2017-3': 37, '2017-2': 16, '2017-1': 43, '2016-10': 57, '2016-11': 23, '2017-5': 52, '2017-4': 42, '2015-5': 29, '2017-7': 33, '2015-7': 46, '2015-6': 61, '2015-3': 26, '2015-8': 37, '2016-6': 50, '2016-7': 33, '2016-4': 33, '2016-5': 29, '2016-2': 27, '2017-6': 37, '2016-1': 44, '2018-4': 9, '2018-1': 65, '2016-8': 45, '2018-3': 45, '2018-2': 43, '2015-4': 71, '2016-9': 25, '2017-9': 33, '2017-8': 186, '2015-9': 48, '2015-2': 1, '2016-12': 27}
for key in sorted(hist):
print "%s: %s" % (key, hist[key])
total = 0
for v in hist.values():
total = total + v
print total
1656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment