Ejemplo n.º 1
0
def list_by_status(chatid):
    cursor = list(db.search_packages_per_user(chatid))
    waiting_payment = get_packages_by_status('Aguardando pagamento', cursor,
                                             chatid)
    payed = get_packages_by_status('Pagamento confirmado', cursor, chatid)
    not_available = get_packages_by_status('Aguardando recebimento pela ECT',
                                           cursor, chatid)
    no_payment = get_packages_by_status('Fiscalização aduaneira finalizada',
                                        cursor, chatid)
    in_transit = get_packages_by_status('Objeto em trânsito', cursor, chatid)
    delivery = get_packages_by_status('saiu para entrega', cursor, chatid)
    tribute = get_packages_by_status('tributo', cursor, chatid)
    refused = get_packages_by_status('recusou o objeto', cursor, chatid)
    exported = get_packages_by_status('unidade de exportação', cursor, chatid)
    not_delivered = get_packages_by_status('Entrega não realizada', cursor,
                                           chatid)
    pickup = get_packages_by_status('retirada', cursor, chatid)
    waiting_action = get_packages_by_status('ação é necessária', cursor,
                                            chatid)
    posted = get_packages_by_status('Objeto postado', cursor, chatid)
    returned = get_packages_by_status('Devolução', cursor, chatid)
    customs = get_packages_by_status('aduaneira', cursor, chatid)
    received_br = get_packages_by_status('Correios do Brasil', cursor, chatid)
    not_answered = get_packages_by_status('Carteiro não atendido', cursor,
                                          chatid)
    not_arrived = get_packages_by_status('Objeto ainda não chegou à unidade',
                                         cursor, chatid)
    try:
        send_status_sorted(bot, chatid, 1, waiting_payment)
        send_status_sorted(bot, chatid, 2, payed)
        send_status_sorted(bot, chatid, 3, not_available)
        send_status_sorted(bot, chatid, 4, no_payment)
        send_status_sorted(bot, chatid, 5, in_transit)
        send_status_sorted(bot, chatid, 6, delivery)
        send_status_sorted(bot, chatid, 7, tribute)
        send_status_sorted(bot, chatid, 8, refused)
        send_status_sorted(bot, chatid, 9, exported)
        send_status_sorted(bot, chatid, 10, not_delivered)
        send_status_sorted(bot, chatid, 11, pickup)
        send_status_sorted(bot, chatid, 12, waiting_action)
        send_status_sorted(bot, chatid, 13, posted)
        send_status_sorted(bot, chatid, 14, returned)
        send_status_sorted(bot, chatid, 15, customs)
        send_status_sorted(bot, chatid, 16, received_br)
        send_status_sorted(bot, chatid, 17, not_answered)
        send_status_sorted(bot, chatid, 18, not_arrived)
    except Exception:
        bot.send_message('9083329', 'Erro MongoBD')
        qtd = -1
Ejemplo n.º 2
0
def list_packages(chatid, done, status):
    '''
    List all packages of a user
    '''
    aux = ''
    try:
        cursor = db.search_packages_per_user(chatid)
        qtd = 0
        for elem in cursor:
            if str(chatid) in elem['users']:
                try:
                    len(elem['stat'])
                except Exception:
                    elem['stat'] = ['Sistema fora do ar']
                if not done:
                    if package_status_can_change(elem):
                        if status:
                            aux = f"{aux}{POSTBOX}<code>{elem['code']}</code>"
                        else:
                            aux = f"{aux}/{elem['code']}"
                        try:
                            if elem[str(chatid)] != elem['code']:
                                aux = f"{aux} <b>{elem[str(chatid)]}</b>"
                            if status:
                                aux = f"{aux}\n{elem['stat'][len(elem['stat'])-1]}\n"
                        except Exception:
                            pass
                        aux = f"{aux}\n"
                        qtd = qtd + 1
                else:
                    if not package_status_can_change(elem):
                        aux = f"{aux}{elem['code']}"
                        try:
                            if elem[str(chatid)] != elem['code']:
                                aux = f"{aux} <b>{elem[str(chatid)]}</b>"
                        except Exception:
                            pass
                        aux = f"{aux}\n"
                        qtd = qtd + 1
    except Exception:
        bot.send_message('9083329', 'Erro MongoBD')
        qtd = -1
    return aux, qtd