Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python that records information to compute daily active users for your site, assuming your site is running with python. :D (obviously)
Assumes you're concerned about the eastern timezone.
from redis import StrictRedis
from datetime import datetime
from pytz import timezone
def log_user(user_id):
Log the user activity for the purpose of a daily active user system.
today ='US/Eastern'))
# daily:user_id:YYYY-MM-DD
key = 'daily:%s:%s' % (user_id, str(
r = StrictRedis(host=REDIS_HOST, port=6379)
r.expire(key, 60 * 60 * 24 * 2) # expires after two days after last update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment