Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created November 5, 2012 18:01
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 ralphbean/4019299 to your computer and use it in GitHub Desktop.
Save ralphbean/4019299 to your computer and use it in GitHub Desktop.
Check active contributors from datanommer
#!/usr/bin/env python
""" Print a list of the contributors whose names have appeared in any event
in the last 60 days
"""
__requires__ = 'datanommer==0.1.8'
import sys
from pkg_resources import load_entry_point
import datanommer.models as m
import fedmsg.config
import datetime
import pprint
def init():
# Load stuff from /etc/fedmsg.d/ into a dict
config = fedmsg.config.load_config(None, [])
m.init(config['datanommer.sqlalchemy.url'])
def handle_bodhi(msg):
""" Given a bodhi message, return the FAS username. """
if 'bodhi.update.comment' in msg.topic:
username = msg.msg['comment']['author']
elif 'bodhi.buildroot_override' in msg.topic:
username = msg.msg['override']['submitter']
else:
username = msg.msg.get('update', {}).get('submitter')
return username
def handle_wiki(msg):
""" Given a wiki message, return the FAS username. """
if 'wiki.article.edit' in msg.topic:
username = msg.msg['user']
elif 'wiki.upload.complete' in msg.topic:
username = msg.msg['user_text']
else:
raise ValueError("Unhandled topic.")
return username
def handle_fas(msg):
""" Given a FAS message, return the FAS username. """
return msg.msg['agent']['username']
# This is a mapping of datanommer models to functions that can extract the
# username from a message of that model type.
username_extractors = {
m.BodhiMessage: handle_bodhi,
m.WikiMessage: handle_wiki,
m.FASMessage: handle_fas,
#m.GitMessage: handle_git,
}
if __name__ == '__main__':
init()
# A list of FAS usernames we're going to build
seen = set()
# TODO -- have this configurable with a switch. 60 days or 90 days.
then = datetime.datetime.now() - datetime.timedelta(days=60)
for model, extractor in username_extractors.items():
query = model.query
query = query.filter(model.timestamp > then)
for msg in query.all():
seen.add(extractor(msg))
print len(seen), "persons seen"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment