From 946dbf4ea040970a2a60dbc98d6f3f0ceda23a3a Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sat, 26 Dec 2015 13:21:33 +0000 Subject: [PATCH] Changed the consumer into a loop --- src/documents/management/commands/consume.py | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/documents/management/commands/consume.py b/src/documents/management/commands/consume.py index 3ab655712..b48f5b6be 100644 --- a/src/documents/management/commands/consume.py +++ b/src/documents/management/commands/consume.py @@ -1,3 +1,4 @@ +import datetime import glob import os import random @@ -12,6 +13,7 @@ from PIL import Image from django.conf import settings from django.core.management.base import BaseCommand +from django.utils import timezone from documents.models import Document @@ -27,6 +29,8 @@ class Command(BaseCommand): 5. Delete the pdf and images """ + LOOP_TIME = 10 # Seconds + CONVERT = settings.CONVERT_BINARY SCRATCH = settings.SCRATCH_DIR CONSUME = settings.CONSUMPTION_DIR @@ -52,8 +56,9 @@ class Command(BaseCommand): try: while True: self.loop() - time.sleep(10) - print(".") + time.sleep(self.LOOP_TIME) + if self.verbosity > 1: + print(".") except KeyboardInterrupt: print("Exiting") @@ -140,7 +145,17 @@ class Command(BaseCommand): sender, title = self._parse_file_name(pdf) - doc = Document.objects.create(sender=sender, title=title, content=text) + stats = os.stat(pdf) + + doc = Document.objects.create( + sender=sender, + title=title, + content=text, + created=timezone.make_aware( + datetime.datetime.fromtimestamp(stats.st_ctime)), + modified=timezone.make_aware( + datetime.datetime.fromtimestamp(stats.st_mtime)), + ) shutil.move(jpgs[0], os.path.join( self.MEDIA_IMG, "{:07}.jpg".format(doc.pk)))