diff --git a/apigeartrack.py b/apigeartrack.py new file mode 100644 index 0000000..4e2035b --- /dev/null +++ b/apigeartrack.py @@ -0,0 +1,50 @@ +import configparser +import json +import requests +import status +import trackingmore +import sys + +config = configparser.ConfigParser() +config.sections() +config.read('bot.conf') + +def getcorreioscode(carrier, code): + url = ('https://geartrack.pt/api/{}?id={}'.format(carrier, code)) + r = requests.get(url) + conteudo = str(r.content.decode('UTF-8')) + a = json.loads(conteudo) + if a['destinyId']: + return(a['destinyId']) + + +def getstatus(code, retries): + carrier = 'cainiao' + code = 'LP00139186175797' + url = ('https://geartrack.pt/api/{}?id={}'.format(carrier, code)) + r = requests.get(url) + conteudo = str(r.content.decode('UTF-8')) + a = json.loads(conteudo) + #print(a) + print(formato_obj(a)) + +def formato_obj(json): + stats = [] + stats.append(str(u'\U0001F4EE') + ' ' + json['id'] + '') + tabela = json['states'] + mensagem = '' + for evento in reversed(tabela): + data = evento['date'] + situacao = evento['state'] + observacao = '' + mensagem = ('Data: {}' + + '\nSituacao: {}' + ).format(data, situacao) + stats.append(mensagem) + if json['destinyId']: + stats.append('Pacote recebido nos Correios.\nCódigo: /' + json['destinyId']) + return stats + + +if __name__ == '__main__': + getstatus(sys.argv[1], 0) diff --git a/apitrackingmore.py b/apitrackingmore.py index 2fe8139..3fe9b6f 100644 --- a/apitrackingmore.py +++ b/apitrackingmore.py @@ -50,7 +50,7 @@ def get_carriers(code): if type(cursor['carrier']) is dict: return [cursor['carrier']] return cursor['carrier'] - except: + except KeyError: carriers = trackingmore.detect_carrier_from_code(code) carriers.sort(key=lambda carrier: carrier['code']) set_carrier_db(code, carriers)