With the zoho api I consult the mail that has an attachment with this format:
b' Ruta\tDespacho\tFecha Reparto\tRegional\tZona\tSector\tNombre\tTipo
Caja\tFactura\tNumero Caja\tCodigo Cliente\tIdentificacion\tCod Premio/Producto\tDireccion\tCodigo Distrito\tDistri
to\tDescrip Premios/Productos\tCantidad\tCiudad\tTelefono\tReferencia de la Direccion\tCampana\tFecha Despacho\tCons Caja\tCodigo Distribuidor\tDistribuidor\tCelular1\n 18782\t51602\t\t
001\t132\t012\tNELLY MARIBEL TOAPANTA TOAQUIZA\tPEDIDO\t1528806\t1\t132012001\t0504095548\t\tLA VICTORIA SN ANTONIO TELLO\t81\tMULINLIVI\t\t1\tPUJILI\t0\tCASA AZUL DE 1 PISO, VIA PRINCIP
AL POR LA CURVA CERRAMIENTO MAYA PORTON NEGRO CA\t202002\t01/29/2020\t14\t135\tMARIANA ESPINOZA SANTILLAN\t0984044011\n'
I am wanting to be able to convert it to csv and be able to format it in python: I see many examples but most do it by opening the file but not with the content directly: in this way:
import csv
with open('archivo.csv') as csvfile:
reader = csv.DictReader(csvfile)
#y aqui poder manejarlo como diccionario
for row in reader:
print(row['Ruta'], row['Despacho'])
but I don't see the way how to pass it to csv format and then handle it as a dictionary.
This is a solution
OUTPUT
Well, in case someone needs to do something similar, I solved it in the following way:
I first converted the format from bytes to str in order to work:
Then I split the \n to separate the rows and a lambda function \t to separate the columns:
and we obtain in this case 3 lists of this form:
Where the first list, by law, are the headers and I store them in a separate list to later match them with their value:
And finally I go through the list (data_list) with enumerate that I use to have the index, since if I want to have the index I would have to create a counter and I didn't want the XD code to look ugly:
Resulting:
I hope it helps someone :D!