fix
[wolnelektury.git] / src / stats / models.py
index ea1a790..c1b4d16 100644 (file)
@@ -1,4 +1,6 @@
 import re
+from urllib.request import urlopen
+from django.apps import apps
 from django.conf import settings
 from django.db import models
 
@@ -12,6 +14,7 @@ class Visits(models.Model):
 
     @classmethod
     def build_month(cls, year, month):
+        Book = apps.get_model('catalogue', 'Book')
         ### TODO: Delete existing?
 
         date = f'{year}-{month:02d}'
@@ -22,15 +25,15 @@ class Visits(models.Model):
             m = re.match('^/katalog/lektura/([^,]+)\.html,', line)
             if m is not None:
                 slug = m.group(1)
-                _url, uviews, views = line.split(',', 3)
+                _url, uviews, views, _rest = line.split(',', 3)
                 uviews = int(uviews)
                 views = int(views)
                 try:
                     book = Book.objects.get(slug=slug)
-                except Book.DoesNotExists:
+                except Book.DoesNotExist:
                     continue
                 else:
                     cls.objects.create(
                         book=book, year=year, month=month,
-                        views=views, uviews=uviews
+                        views=views, unique_views=uviews
                     )