Created
June 24, 2016 13:27
-
-
Save pstrinkle/541ba8ca06c96b8511e2f6ab188f190e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 = datetime.now(timezone('US/Eastern')) | |
# daily:user_id:YYYY-MM-DD | |
key = 'daily:%s:%s' % (user_id, str(today.date())) | |
r = StrictRedis(host=REDIS_HOST, port=6379) | |
r.incr(key) | |
r.expire(key, 60 * 60 * 24 * 2) # expires after two days after last update | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment