From 0f5e8974169a2492ef253a94950e0e75e041d8cb Mon Sep 17 00:00:00 2001 From: Marco Rougeth Date: Mon, 7 Oct 2019 21:47:47 +0000 Subject: [PATCH] Update apitrackingmore.py --- apitrackingmore.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apitrackingmore.py b/apitrackingmore.py index 844204e..0110179 100644 --- a/apitrackingmore.py +++ b/apitrackingmore.py @@ -43,17 +43,17 @@ def get_or_create_tracking_item(carrier, code): def get_carriers(code): - cursor = db.rastreiobot.find_one({ + package = db.rastreiobot.find_one({ "code": code }) - try: - if type(cursor['carrier']) is dict: - return [cursor['carrier']] - return cursor['carrier'] - except: - carriers = trackingmore.detect_carrier_from_code(code) - carriers.sort(key=lambda carrier: carrier['code']) - set_carrier_db(code, carriers) + + if package: + carriers = package['carrier'] + return carriers if isisntance(carriers, list) else list(carriers) + + carriers = trackingmore.detect_carrier_from_code(code) + carriers.sort(key=lambda carrier: carrier['code']) + set_carrier_db(code, carriers) return carriers