From ccd0453cd6c08ae4954584ab2cd92b7f9283f010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dzikie=20dro=C5=BCd=C5=BCe?= Date: Fri, 29 Nov 2013 20:16:10 +0100 Subject: [PATCH] perfect... --- src/papiezator/pope_utils.py | 18 +++++++---- .../templates/papiezator/index.html | 8 ++--- src/populate_popes | 30 ++++++++++++------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/papiezator/pope_utils.py b/src/papiezator/pope_utils.py index e0c93a3..e823b0b 100644 --- a/src/papiezator/pope_utils.py +++ b/src/papiezator/pope_utils.py @@ -4,6 +4,9 @@ from PIL import Image from io import BytesIO # FIXME: def select_best_pope(aspect_ratio): + """ (float) -> Pope + + """ pp = PerfectPope.objects.filter(aspect_ratio=aspect_ratio) if pp: return pp[0].pope @@ -38,12 +41,15 @@ def habemus_papam(aspect_ratio, pope): def read_pope(width, height, pope): - im = Image.open(pope.path) - im = im.resize((width, height)) - f = BytesIO() # FIXME: ceriously. - im.save(f, "jpeg") - f.seek(0) - return f.read() + """ (int, int, Pope) -> bytes + + """ + im = Image.open(pope.path) + im = im.resize((width, height)) + f = BytesIO() # FIXME: ceriously. + im.save(f, "jpeg") + f.seek(0) + return f.read() class PopeMaster: diff --git a/src/papiezator/templates/papiezator/index.html b/src/papiezator/templates/papiezator/index.html index d5149fc..a322b79 100644 --- a/src/papiezator/templates/papiezator/index.html +++ b/src/papiezator/templates/papiezator/index.html @@ -39,13 +39,13 @@

Get your popes

- - + +

Get your popes today

- - + +
diff --git a/src/populate_popes b/src/populate_popes index 0c38716..3547cfd 100644 --- a/src/populate_popes +++ b/src/populate_popes @@ -1,23 +1,33 @@ +#!/usr/bin/env python import os os.environ ['PYTHONPATH'] = '/home/daz/Documents/Projects/Py/django/papiez_ipsum' os.environ['DJANGO_SETTINGS_MODULE'] = 'papiez_ipsum.settings' -#!/usr/bin/env python from papiezator.models import Pope, PopeVersion from papiezator.pope_utils import PopeMaster from os import path +from optparse import OptionParser PREFIX = "popes" pm = PopeMaster() -with open('popes/JP2_list') as file: - jp2 = PopeVersion(0, "John Paul II") - jp2.save() - for line in file: - pope = line.rstrip() - p = pm.parse_pope(path.join(PREFIX, pope)) - p.pope_version = jp2 - p.save() - print(p) + +def main(): + parser = OptionParser() + options, args = parser.parse_args() + + with open('popes/JP2_list') as file: + jp2 = PopeVersion(0, "John Paul II") + jp2.save() + for line in file: + pope = line.rstrip() + p = pm.parse_pope(path.join(PREFIX, pope)) + p.pope_version = jp2 + p.save() + print(p) + + +if __name__ == '__main__': + main()