Exemplo n.º 1
0
metadata_type = pd.DataFrame(
    columns=['instalacao', 'colecao', 'metadata', 'metadata_type'])

#Get collection table from database
collection_db = pd.read_sql_table('colecao', dbConnection)

#Get itens table from database
itens_db_col = pd.read_sql_table('itens', dbConnection)
itens_db_col = itens_db_col.drop(columns=['id'])

#Collect data installation, colections and metadata
for i in range(len(api.install_dict['id'])):
    print("Verificando a Instalação {}".format(api.install_dict['name'][i]))

    #Requisita os dados de coleção
    collections_resp = functions.try_request(api.install_dict["url"][i] +
                                             api.dict_endpoint['col_endpoint'])

    #Pula se nenhuma coleção for encontrada no endpoint
    if collections_resp.json() == []:
        print("Coleção não encontrada para a instalação {}".format(
            api.install_dict['name'][i]))
        continue

    #Itera entre a coleções encontradas
    for collection in collections_resp.json():

        #Verifica se a coleção é uma das selecionadas para compor o banco de dados integrado
        if collection['name'] in inbcm.selected_col[api.install_dict['name']
                                                    [i]]:

            #Cria variáveis para o nome da instalação, o id da coleção e o nome da coleção
Exemplo n.º 2
0
#Collect data from terms endpoint on Tainacan API per Installation
terms_table = pd.DataFrame(columns=tables.dfTables['term'])

#Used on hierarchy dealing
termTax_df = pd.DataFrame(columns=tables.dfTables['term_tax'])

#Get taxonomy and term table from database
taxonomy_db = pd.read_sql_table('taxonomia', dbConnection)
terms_db = pd.read_sql_table('termos', dbConnection)

for i in range(len(api.install_dict['id'])):

    print("Verificando a Instalação {}".format(api.install_dict['name'][i]))

    #Terms are get by taxonomies, so we need to repeat the process of getting taxonomy data above
    taxonomy_resp = functions.try_request(api.install_dict['url'][i] +
                                          api.dict_endpoint['tax_endpoint'])
    paged = 0

    while taxonomy_resp.json() != []:
        paged += 1

        print("Verificando a página {} de taxonomias".format(paged))
        taxonomy_resp = functions.try_request(
            api.install_dict['url'][i] + api.dict_endpoint['tax_endpoint'] +
            "/?paged={}".format(paged))

        for taxonomy in taxonomy_resp.json():
            print("Verificando os termos taxonomia {}".format(
                taxonomy['name']))
            term_resp = functions.try_request(
                api.install_dict['url'][i] +
Exemplo n.º 3
0
mysqlEngine = create_engine('mysql+pymysql://user:password@localhost:3306/tainacan_api')
dbConnection = mysqlEngine.connect()

#Collect data from taxonomy endpoint on Tainacan API per Installation
#Truncate Taxonmy table
#functions.truncate_table('taxonomia')

#Cria dataframe com as colunas da tabela de taxonomia
taxonomies_table = pd.DataFrame(columns=tables.dfTables['taxonomy'])


for i in range(len(api.install_dict['id'])):
    
    print("Verificando a instalação {}".format(api.install_dict['name'][i]))
    
    taxonomy_resp = functions.try_request(api.install_dict['url'][i]+api.dict_endpoint['tax_endpoint'])
    paged = 0
        
    #The response of API came in a interval of 10 results perpage, we used while to interate between the result pages, until there is no more result to show
    while taxonomy_resp != []:
        
        paged += 1
        print("Verificando a página {} de taxonomias".format(paged))
        taxonomy_resp = functions.try_request(api.install_dict['url'][i]+api.dict_endpoint['tax_endpoint']+"/?paged={}".format(paged)).json()
        
        for taxonomy in taxonomy_resp:
            
            print("Verificando a taxonomia {}".format(taxonomy['name']))
            if taxonomy['name'] in taxonomies_table['name'].to_list():
                continue
            else:
Exemplo n.º 4
0
#Convert the installation DataFrame to a SQL Table
pd.DataFrame.from_dict(api.install_dict).to_sql('instalacao',
                                                dbConnection,
                                                if_exists='append',
                                                chunksize=1000,
                                                index=False)

#Collect data from collection endpoint on Tainacan API per Installation
for i in range(len(api.install_dict['id'])):

    #Reset the collection dataframe for each instalation.
    collection_table = pd.DataFrame(columns=tables.dfTables['collection'])

    print("Verificando a instalação {}".format(api.install_dict['name'][i]))

    r = functions.try_request(api.install_dict["url"][i] +
                              api.dict_endpoint['col_endpoint'])

    if r.json() == []:
        print("Resultado Nulo")
        collection_table = collection_table.append(
            {
                'id_instalacao': api.install_dict['id'][i],
                'name': "Requisição vazia",
                'description': "Requisição vazia",
                'creation_date': "Requisição vazia",
                'modification_date': "Requisição vazia",
                'url': "Requisição vazia"
            },
            ignore_index=True)

    for collection in r.json():