Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Created January 11, 2013 17:54
Show Gist options
  • Select an option

  • Save felipe-prenholato/4512664 to your computer and use it in GitHub Desktop.

Select an option

Save felipe-prenholato/4512664 to your computer and use it in GitHub Desktop.
rascunhos para uma app em cima do cepbr
def get_cep(cep):
# cache = django cache
# CepCache = model para cachear os ceps
cached = cache.get(cep)
if not cached:
try:
dbcep = CepCache.objects.get(cep=cep)
except CepCache.DoesNotExist:
from cepbr import Cep
dbcep = CepCache.objects.create(**Cep(cep))
finally:
cache.set(cep, dbcep.asdict(), 60 * 60 * 48)
return dbcep.asdict()
else:
return cached
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment