コード例 #1
0
def get_carriers(code):
    cursor = db.search_package(code)
    try:
        if type(cursor['carrier']) is dict:
            return [cursor['carrier']]
        return cursor['carrier']
    except:
        try:
            carriers = trackingmore.detect_carrier_from_code(code)
        except Exception as e:
            print(e)
            raise IndexError
        carriers.sort(key=lambda carrier: carrier['code'])
        db.update_package(code, carrier=carriers)
    return carriers
コード例 #2
0
def get(code, retries=0):
    try:
        carriers = get_carriers(code)
    except IndexError:
        return status.TYPO
    except trackingmore.trackingmore.TrackingMoreAPIException as e:
        return status.NOT_FOUND_TM

    response_status = status.NOT_FOUND_TM
    for carrier in carriers:
        try:
            if carrier['code'] == 'correios':
                codigo_novo = db.search_package(code)["code_br"]
                return correios.get(codigo_novo, 3)
        except TypeError:
            pass
        try:
            tracking_data = get_or_create_tracking_item(carrier['code'], code)
            print(tracking_data)
        except trackingmore.trackingmore.TrackingMoreAPIException as e:
            if e.err_code == 4019 or e.err_code == 4021:
                response_status = status.OFFLINE
            elif e.err_code == 4031:
                response_status = status.NOT_FOUND_TM
        else:
            if not tracking_data or 'status' not in tracking_data:
                response_status = status.OFFLINE
            elif tracking_data['status'] == 'notfound':
                response_status = status.NOT_FOUND_TM
                print(tracking_data)
            #elif len(tracking_data) >= 10:
            elif tracking_data['status'] == 'transit':
                db.update_package(code, carrier=carrier)
                return formato_obj(tracking_data, carrier, code, retries)
            elif tracking_data['status'] == 'expired':
                db.update_package(code, carrier=carrier)
                return formato_obj(tracking_data, carrier, code, retries)
            elif tracking_data['status'] == 'delivered':
                db.update_package(code, carrier=carrier)
            elif tracking_data['status'] == 'pickup':
                db.update_package(code, carrier=carrier)
                return formato_obj(tracking_data, carrier, code, retries)

    return response_status
コード例 #3
0
def check_package(code):
    cursor = db.search_package(code)
    if cursor:
        return True
    return False
コード例 #4
0
 ):
     continue
 elif 'objeto devolvido' in old_state.lower():
     continue
 elif 'objeto roubado' in old_state.lower():
     continue
 elif 'delivered' in old_state.lower():
     continue
 try:
     stat = get_package(code)
 except:
     sleep(3000)
     stat = get_package(code)
 if stat == 0:
     break
 cursor2 = db.search_package(code)
 try:
     len_new_state = len(cursor2['stat'])
 except:
     len_new_state = 1
 if len_old_state != len_new_state:
     len_diff = len_new_state - len_old_state
     for user in elem['users']:
         logger_info.info(
             str(datetime.now()) + ' ' + multiple + ' ' +
             str(code) + ' \t' + str(user) + ' \t' + str(sent) +
             '\t' + str(timediff) + '\t' + str(len_old_state) +
             '\t' + str(len_new_state) + '\t' + str(len_diff))
         try:
             try:
                 message = (str(u'\U0001F4EE') + '<b>' + code +