Created
June 12, 2018 18:15
-
-
Save lopinho/25cb5957ecd46e422843691fb5e5d3fd to your computer and use it in GitHub Desktop.
Criando um csv no terminal com dados dos arrematantes do DT01-17
This file contains 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 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