Skip to content

Instantly share code, notes, and snippets.

@lopinho
Created June 12, 2018 18:15
Show Gist options
  • Save lopinho/25cb5957ecd46e422843691fb5e5d3fd to your computer and use it in GitHub Desktop.
Save lopinho/25cb5957ecd46e422843691fb5e5d3fd to your computer and use it in GitHub Desktop.
Criando um csv no terminal com dados dos arrematantes do DT01-17
from django.utils.encoding import smart_str
from django.core.mail import EmailMessage
from leilao.models import *
leilao = Leilao.objects.get(nome='DT01-17')
arremates = leilao.arremates_do_leilao_queryset()
colunas = ['Lote', 'username', 'arremate', 'cpf']
texto = ";".join(colunas)
for dados in arremates.values_list('lote__numero_do_lote_no_leilao', 'user__username', 'valor', 'user__userprofile__cpf'):
texto += "\n{}".format(";".join(map(smart_str, dados)))
email = EmailMessage('Dados do leilão DT01-17', 'csv em anexo', 'sistema-nao-responder@brbid.com', ['lopinho@gmail.com'])
email.attach('dados.csv', texto, 'text/csv')
email.send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment