Created
November 12, 2014 09:21
-
-
Save slaporte/3f4a386c6e6c7caaecfc to your computer and use it in GitHub Desktop.
A WSGI app for Tool Labs to fetch the top editors for a wiki
This file contains hidden or 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
| from bottle import route, default_app, debug | |
| from flup.server.fcgi import WSGIServer | |
| from datetime import timedelta, datetime | |
| import os | |
| import oursql | |
| #import jsonp_bottle | |
| def parse_date_string(stamp): | |
| return datetime.strptime(stamp, '%Y%m%d%H%M%S') | |
| @route('/<db>/<num>') | |
| def get_top_editors(db, num): | |
| ret = '' | |
| db = oursql.connect(db='%s_p' % db, | |
| host='%s.labsdb' % db, | |
| read_default_file=os.path.expanduser('~/replica.my.cnf'), | |
| charset=None, | |
| use_unicode=False) | |
| cursor = db.cursor(oursql.DictCursor) | |
| cursor.execute(''' | |
| SELECT user.user_name, | |
| user.user_editcount | |
| FROM user | |
| WHERE user_id NOT IN (SELECT ug_user | |
| FROM user_groups | |
| WHERE ug_group = 'bot') | |
| ORDER BY user_editcount | |
| DESC | |
| LIMIT ?; | |
| ''', (num,)) | |
| for editor in cursor.fetchall(): | |
| ret = ret + editor['user_name'] + ' / ' + str(int(editor['user_editcount'])) + '<br/>\n' | |
| return ret | |
| @route('/') | |
| def get_default(): | |
| return 'try /db/num/ <br/> Please refer to http://noc.wikimedia.org/conf/all.dblist for a list of databases' | |
| app = default_app() | |
| debug(False) | |
| if __name__ == '__main__': | |
| WSGIServer(app).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment