Created
March 14, 2023 23:43
-
-
Save Edclydson/e791fa109d740d9563dd04c656b2e6f9 to your computer and use it in GitHub Desktop.
Consumindo API de Dados Aberto Fortaleza da Citinova
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
import json | |
import pandas as pd | |
from urllib import request | |
# Get the data from the API | |
arquivo_local = "C:\\Users\\edcly\\Downloads" \ | |
"\\transparencia_informacoes_servidores_012021.csv" | |
url = "https://dados.fortaleza.ce.gov.br/api/3/action/package_search" | |
def ckan_package_search_organizations(url, organizacao): | |
query = "?fq=organization:" | |
retorno = request.urlopen(url + query + organizacao) | |
json_retorno = json.loads(retorno.read()) | |
return json.dumps(json_retorno, indent = 4, sort_keys = True, | |
ensure_ascii = False) | |
def ckan_package_search_groups(url, grupo): | |
query = "?fq=groups:" | |
retorno = request.urlopen(url + query + grupo) | |
json_retorno = json.loads(retorno.read()) | |
return json.dumps(json_retorno, indent = 4, sort_keys = True, | |
ensure_ascii = False) | |
def ckan_package_search_tags(url, tag): | |
query = "?fq=tags:" | |
retorno = request.urlopen(url + query + tag) | |
json_retorno = json.loads(retorno.read()) | |
return json.dumps(json_retorno, indent = 4, sort_keys = True, | |
ensure_ascii = False) | |
def ckan_package_search_format(url, formato): | |
query = "?fq=res_format:" | |
formato = formato.upper() | |
retorno = request.urlopen(url + query + formato) | |
json_retorno = json.loads(retorno.read()) | |
return json.dumps(json_retorno, indent = 4, sort_keys = True, | |
ensure_ascii = False) | |
def ckan_package_search_license(url, licenca): | |
query = "?fq=license_id:" | |
retorno = request.urlopen(url + query + licenca) | |
json_retorno = json.loads(retorno.read()) | |
return json.dumps(json_retorno, indent = 4, sort_keys = True, | |
ensure_ascii = False) | |
def dataset_local(arquivo_local): | |
# Read the file | |
df = pd.read_csv(arquivo_local) | |
# Print the first 5 rows of the data | |
print(df.head()) | |
# Print the last 5 rows of the data | |
print(df.tail()) | |
# Print the number of rows and columns | |
print(df.shape) | |
# Print the column names | |
print(df.columns) | |
# Print the data type of each column | |
print(df.dtypes) | |
# Print the summary statistics for each of the numeric columns | |
print(df.describe()) | |
# Print the unique values for each of your categorical columns | |
print(df["NOME DO SERVIDOR"].unique()) | |
# Print the Dataframe information | |
print(pd.DataFrame(df["NOME DO SERVIDOR"] + ["ENTIDADE OU ÓRGÃO"] + [ | |
"REMUNERAÇÃO"])) | |
if __name__ == "__main__": | |
print("Dataset Local Consuming") | |
dataset_local(arquivo_local) | |
print("="*10) | |
print("Dataset Remote Consuming:\n") | |
print("Dataset Remote Consuming by Organization") | |
print(ckan_package_search_organizations(url, "sepog")) | |
print("="*10) | |
print("Dataset Remote Consuming by Group") | |
print(ckan_package_search_groups(url, "meioambiente")) | |
print("="*10) | |
print("Dataset Remote Consuming by Tag") | |
print(ckan_package_search_tags(url, "cgm")) | |
print("="*10) | |
print("Dataset Remote Consuming by Format") | |
print(ckan_package_search_format(url, "csv")) | |
print("="*10) | |
print("Dataset Remote Consuming by License") | |
print(ckan_package_search_license(url, "cc-by-sa")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment