import requests
import pandas as pd


BASE_DATA_DIR = './data/'

def fetch_suppliers():
    raw_suppliers = []
    first_response = requests.get('http://compras.dados.gov.br/fornecedores/v1/fornecedores.json').json()
    raw_suppliers = raw_suppliers + first_response['_embedded']['fornecedores']

    last_page = first_response['count']
    for page in range(2, last_page):
        print('{}/{}'.format(page, last_page))
        response = requests.get('http://compras.dados.gov.br/fornecedores/v1/fornecedores.json').json()
        raw_suppliers = raw_suppliers + first_response['_embedded']['fornecedores']
    return raw_suppliers


def prepare_data(raw_data):
    suppliers_attributes_columns = {'id': 'id', 'cnpj': 'cnpj', 'nome': 'name', 'ativo': 'active',
    'recadastrado': 'relisted', 'id_municipio': 'city_id', 'uf': 'state', 'id_natureza_juridica': 'legal_nature_id',
    'id_porte_empresa': 'company_size_id', 'id_ramo_negocio': 'business_id', 'id_unidade_cadastradora': 'responsible_entity',
    'id_cnae': 'cnae_id', 'habilitado_licitar': 'allowed_to_bid'}

    df = pd.DataFrame(raw_data, columns = suppliers_attributes_columns.keys())

    return df


def save_csv(df):
    df.to_csv(path_or_buf=BASE_DATA_DIR+'purchase_suppliers.xz', sep=',', compression='xz', encoding='utf-8', index=False)

def main():
    raw_data = fetch_suppliers()
    suppliers_info = prepare_data(raw_data)
    save_csv(suppliers_info)

if __name__ == '__main__':
    main()

@@ -694,16 +694,25 @@
 umns = %7B
+%0A        
 'id': 'i
@@ -714,16 +714,24 @@
 ': 'id',
+%0A       
  'cnpj':
@@ -738,16 +738,24 @@
  'cnpj',
+%0A       
  'nome':
@@ -762,16 +762,24 @@
  'name',
+%0A       
  'ativo'
@@ -794,16 +794,20 @@
 e',%0A    
+   
+ 
 'recadas
@@ -825,16 +825,24 @@
 listed',
+%0A       
  'id_mun
@@ -860,16 +860,24 @@
 ity_id',
+%0A       
  'uf': '
@@ -883,16 +883,24 @@
 'state',
+%0A       
  'id_nat
@@ -931,24 +931,28 @@
 nature_id',%0A
+    
     'id_port
@@ -977,24 +977,32 @@
 ny_size_id',
+%0A       
  'id_ramo_ne
@@ -1023,16 +1023,24 @@
 ess_id',
+%0A       
  'id_uni
@@ -1081,24 +1081,28 @@
 ntity',%0A    
+ 
+   
 'id_cnae': '
@@ -1110,16 +1110,24 @@
 nae_id',
+%0A       
  'habili

Improve readability