def process_response(self, request, response): """Add the request data to the stats""" if not str(response.status_code) == '200': return response for path in settings.STATS_EXCLUDE: if path in request.path: return response day, created = Day.objects.get_or_create(date=datetime.date.today(), defaults={'stats': '{}', 'date': datetime.date.today()}) # load the stats data stats = eval(day.stats) process_request(request, stats, {'site': Site.objects.get_current().domain}) day.stats = str(stats) day.save() return response
def logparse(logfile): """Import an Apache or Lighttpd access log and save it for Conescy Stats. Currently, you cannot specify any format, it will just parse assuming it's in Apache's default format. This is e.g. something like that:: 91.13.116.4 pascalhertleif.de - [28/Jun/2008:20:29:39 +0000] "GET / HTTP/1.1" 200 3675 "http://killercup.de/?page=2" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9) Gecko/2008052906 Firefox/3.0" 'ip domain - [Date:Time timezone] "METHODE path PROTOCOL/VERSION" statuscode processnumber "refer" "UserAgent"' Also, if you send larger files to this function, it can take some time to process it all. """ # let there be a dict. s = {} i = False for line in logfile: # parse this, snake!! r = re.search(format, line) # should I really have a look at this line? if r.group("path").startswith(settings.STATS_EXCLUDE): # - no, if path is excluded by setting continue if not str(r.group("status")) == "200": # - no, if the request returned an error continue day = parse(r.group("date")).date() # on the first run of each day, load 's' from the db if not i == str(day): s = loginit(s, day) # make a Django request object request = Request(r) if not s.get(str(day), False): s[str(day)] = {} s[str(day)] = process_request(request, s[str(day)]) del request i = True return s