From dc5aecc5b3a508a6a7992f30a065ca49d68f2b80 Mon Sep 17 00:00:00 2001 From: Vinta Date: Thu, 24 Oct 2013 03:52:21 +0800 Subject: [PATCH] add to_ordered_dict() --- haul/core.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/haul/core.py b/haul/core.py index 4032e57..8de1ef6 100644 --- a/haul/core.py +++ b/haul/core.py @@ -1,5 +1,6 @@ # coding: utf-8 +from collections import OrderedDict import mimetypes import re @@ -191,8 +192,8 @@ class HaulResult(object): """ def __init__(self): - self.content_type = None self.url = None + self.content_type = None self.title = None self.finder_image_urls = [] self.extender_image_urls = [] @@ -216,3 +217,18 @@ def image_urls(self): def to_dict(self): return self.__dict__ + + def to_ordered_dict(self): + order_keys = ( + 'url', + 'content_type', + 'title', + 'finder_image_urls', + 'extender_image_urls', + ) + + d = OrderedDict() + for key in order_keys: + d[key] = getattr(self, key) + + return d