A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals, absolute_import
  3. """Endpoints for visitor tracking functions."""
  4. from flask import Blueprint, g
  5. import re
  6. import rophako.model.tracking as Tracking
  7. from rophako.utils import template
  8. mod = Blueprint("tracking", __name__, url_prefix="/tracking")
  9. @mod.route("/")
  10. def index():
  11. return template("tracking/index.html")
  12. @mod.route("/visitors")
  13. def visitors():
  14. g.info["history"] = Tracking.get_visitor_details()
  15. return template("tracking/visitors.html")
  16. @mod.route("/referrers")
  17. def referrers():
  18. g.info["referrers"] = Tracking.get_referrers()
  19. # Filter some of the links.
  20. for i, link in enumerate(g.info["referrers"]["referrers"]):
  21. # Clean up useless Google links.
  22. if "google" in link[0] and re.search(r'/(?:imgres|url|search|translate\w+)?/', link[0]):
  23. g.info["referrers"]["referrers"][i] = None
  24. # Make the links word-wrap properly.
  25. filtered = [
  26. [ re.sub(r'(.{20})', r'\1<wbr>', x[0]), x[1] ]
  27. for x in g.info["referrers"]["referrers"]
  28. if x is not None
  29. ]
  30. g.info["referrers"]["referrers"] = filtered
  31. return template("tracking/referrers.html")