@@ -0,0 +1,2137 @@
+##%0A#    Copyright (C) 2014 Jessica Tallon & Matt Molyneaux%0A#   %0A#    This file is part of Inboxen.%0A#%0A#    Inboxen is free software: you can redistribute it and/or modify%0A#    it under the terms of the GNU Affero General Public License as published by%0A#    the Free Software Foundation, either version 3 of the License, or%0A#    (at your option) any later version.%0A#%0A#    Inboxen is distributed in the hope that it will be useful,%0A#    but WITHOUT ANY WARRANTY; without even the implied warranty of%0A#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A#    GNU Affero General Public License for more details.%0A#%0A#    You should have received a copy of the GNU Affero General Public License%0A#    along with Inboxen.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A##%0A%0Aimport pprint%0Aimport sys%0A%0Afrom django.core.management.base import BaseCommand, CommandError%0Afrom django.core.urlresolvers import resolve, Resolver404%0A%0A_help = %22%22%22%0AGiven a list of URLs, will display statistics for named URLs.%0A%0ASingle argument is either a file path or '-' for stdin.%0A%0ATo use with your HTTPd logs, use the %22awk%22 command to pull the URLs out. For%0Aexample, given a log file where the URL is the third item on a line:%0A%0A    awk '%7Bprint $3%7D' /path/to/access.log %7C python manage.py url_stats -%0A%22%22%22%0A%0Aclass Command(BaseCommand):%0A    args = %22%3Cfile%3E %7C -%22%0A    help = _help%0A%0A    def handle(self, *args, **options):%0A        if len(args) != 1:%0A            raise CommandError(%22This command expects either a file name or '-' for stdin%22)%0A        if args%5B0%5D.strip() == %22-%22:%0A            file_obj = sys.stdin%0A        else:%0A            file_obj = open(args%5B0%5D, %22r%22)%0A%0A        pp = pprint.PrettyPrinter(indent=4)%0A%0A        urls = %7B%7D%0A        non_match = set()%0A        for url in file_obj:%0A            try:%0A                name = resolve(url).url_name%0A            except Resolver404:%0A                non_match.add(url)%0A                continue%0A%0A            if name in urls:%0A                urls%5Bname%5D = urls%5Bname%5D + 1%0A            else:%0A                urls%5Bname%5D = 1%0A%0A        print %22URLs:%22%0A        pp.pprint(urls)%0A%0A        print %22Non-matches:%22%0A        pp.pprint(non_match)%0A%0A

Add url_stats command