Created
November 4, 2015 13:42
-
-
Save fchevitarese/52aa7695c06dc9ddcb7f to your computer and use it in GitHub Desktop.
classe.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree import ElementTree as ET | |
import requests | |
import json | |
import xmltodict | |
class buscaCliente(object): | |
def __init__(self, serv_id, codigo, descricao): | |
self.serv_id=serv_id | |
self.codigo = codigo | |
self.descricao = descricao | |
def retorno(): | |
xml_data = """ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" | |
xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/"> | |
<soapenv:Header/> | |
<soapenv:Body> | |
<cli:buscaCliente> | |
<idContrato>9912331062</idContrato> | |
<idCartaoPostagem>0067511082</idCartaoPostagem> | |
<usuario>14172907</usuario> | |
<senha>jq5y6</senha> | |
</cli:buscaCliente> | |
</soapenv:Body> | |
</soapenv:Envelope>""" | |
headers = {'Content-Type': 'application/xml'} | |
result = requests.post('https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl', | |
data=xml_data, headers=headers, verify=False).text | |
data = json.loads(json.dumps(xmltodict.parse(result))) | |
for k,v in data.items(): | |
servicos = v['soap:Body']['ns2:buscaClienteResponse']['return']['contratos']['cartoesPostagem']['servicos'] | |
# print servicos | |
for s in servicos: | |
busca = buscaCliente(s['id'], s['codigo'], s['descricao']) | |
# buca.save() para salvar no db | |
print(busca.serv_id, busca.codigo, busca.descricao) | |
# correios = buscaCliente() | |
# dados = correios.retorno() | |
retorno() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment