Skip to content

Commit

Permalink
Refatoração do codigo
Browse files Browse the repository at this point in the history
  • Loading branch information
dilannery committed Dec 28, 2010
1 parent f44cb98 commit 01c2bc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Binary file added src/.swp
Binary file not shown.
36 changes: 16 additions & 20 deletions src/correios.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@

import cod

def __getDados(tags_name, dom):
dados = {}

for tag_name in tags_name:
try:
dados[tag_name] = dom.getElementsByTagName(tag_name)[0]
dados[tag_name] = dados[tag_name].childNodes[0].data
except:
dados[tag_name] = ''

return dados

def frete(cod,GOCEP,HERECEP,peso,
comprimento,diametro,toback='xml'):

dados = {}

url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?\
StrRetorno=%s\
&nCdServico=%s\
Expand All @@ -45,18 +55,9 @@ def frete(cod,GOCEP,HERECEP,peso,
'EntregaSabado',
)

for tag_name in tags_name:
try:
dados[tag_name] = dom.getElementsByTagName(tag_name)[0]
dados[tag_name] = dados[tag_name].childNodes[0].data
except:
dados[tag_name] = ''

return dados
return __getDados(tags_name, dom)

def cep(numero):
dados = {}

url = 'http://cep.republicavirtual.com.br/web_cep.php?\
formato=xml&cep=%s' % (str(numero))
dom = minidom.parse(urllib2.urlopen(url))
Expand All @@ -71,14 +72,9 @@ def cep(numero):
resultado = dom.getElementsByTagName('resultado')[0]
resultado = int(resultado.childNodes[0].data)
if resultado != 0:
for tag_name in tags_name:
try:
dados[tag_name] = dom.getElementsByTagName(tag_name)[0]
dados[tag_name] = dados[tag_name].childNodes[0].data
except:
dados[tag_name] = ''

return dados
return __getDados(tags_name, dom)
else:
return {}

# Delete the modules to not show up in the namespace
# del urllib2, sys, minidom

0 comments on commit 01c2bc7

Please sign in to comment.