Looping no request

-1

How can I make a looping to bring request information from a list of coordinates of a csv and take the result to another csv?

import requests
import pandas as pd

parametro = dict(latitude=-23.512294, longitude=-46.667259, status=1, lista=1, limite=96, acessibilidade='')

r = requests.post('https://www.banco24horas.com.br/index/busca-json-terminal', data=parametro)

df = r.json()
display(df)
    
asked by anonymous 05.12.2018 / 13:56

1 answer

0

The value returned after the request is not a "CSV" - (CSVs is a generic name for a file type, nor is it a data format that exists in memory.)

Anyway, since you're already using Pandas, writing a CSV file from the detalhes fault key of that response is trivial. (The answer does not just return a list with information about the ATMs, there are other fields too):

import requests
import pandas as pd

parametro = dict(latitude=-23.512294, longitude=-46.667259, status=1, lista=1, limite=96, acessibilidade='')

r = requests.post('https://www.banco24horas.com.br/index/busca-json-terminal', data=parametro)

df = pd.DataFrame(r.json()['detalhes']
df.to_csv('meu_arquivo.csv')

The .to_csv flame of Pandas already creates the file and writes all serialized data correctly.

    
05.12.2018 / 16:20