From 7d95d6ff8ed51bb11413343d7c17807f0362cb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dzikie=20dro=C5=BCd=C5=BCe?= Date: Mon, 3 Feb 2014 21:10:02 +0100 Subject: [PATCH] Steve broke the regex, lame --- src/populate_popes | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/populate_popes b/src/populate_popes index d7de2a1..fab483f 100644 --- a/src/populate_popes +++ b/src/populate_popes @@ -21,17 +21,15 @@ def init_pope(meta): return pope else: pope = Pope(meta["id"], meta["name"]) - pope.save() return pope def add_pope_entry(pope, path): if pope_or_death(PopeImage, path=path): print('-', end='') - return False + return None pope_image = parse_pope(path) pope_image.pope = pope - pope_image.save() print('+', end='') return pope_image @@ -56,11 +54,15 @@ def main(): existing_popes.append(meta["id"]) pope = init_pope(meta) - with open(pl) as file: + pope_images_batch = [] + with open(pl, 'rU') as file: for line in file: - line = line.rstrip() + line = line.rstrip('\n') line = path.join("popes", line) - add_pope_entry(pope, line) + pope_images_batch.append( + add_pope_entry(pope, line) + ) + PopeImage.objects.bulk_create((x for x in pope_images_batch if x is not None)) if __name__ == '__main__':