Ejemplo n.º 1
0
def get_uris():
    cursor = admin.login_db()
    #perhaps change these to be arguments...there are a few other things to fix too.
    note_type = input(
        'Please enter the type of resource-level note to search: ')
    repository_num = input('Please enter your repository number: ')
    #create list from ead ids in text file
    outfile = input('Please enter path to input EAD list: ')
    eadlist = open(outfile, 'r')
    eadlisty = eadlist.read().split('\n')
    #sometimes a newline gets stuck in there - this takes care of that
    if eadlisty[-1] == '':
        del eadlisty[-1]
    moveon = input('Please press enter to run query...')
    print(moveon)
    #text file to store eads that don't have notes of the selected type attached
    textfile = input('Please enter path to output text file: ')
    output = open(textfile, 'a')
    #CSV file to store query data
    csvfile = input('Please enter path to output CSV: ')
    #needs headers in output CSV
    for ead in eadlisty:
        print('querying ' + ead)
        cursor.execute("""
        SELECT resource.ead_id AS EAD_ID
            , resource.identifier AS Identifier
            , resource.title AS Resource_Title
#            , ev.value AS Level
#            , CAST(note.notes as CHAR (20000) CHARACTER SET UTF8) AS Note_Text
            , CONCAT('/repositories/', resource.repo_id, '/resources/', resource.id) AS Resource_URL
#            , note_persistent_id.persistent_id AS Persistent_ID
        FROM resource
#        LEFT JOIN note_persistent_id on note_persistent_id.note_id = note.id
#        LEFT JOIN resource on note.resource_id = resource.id
#        LEFT JOIN enumeration_value ev on ev.id = resource.level_id
        WHERE resource.repo_id = """ + repository_num + """ 
#        AND note.notes LIKE '%""" + note_type + """%'
        AND resource.ead_id LIKE '""" + ead + """'""")
        #add columns later...
        #        columns = cursor.description
        result = cursor.fetchall()
        #if no results, write ead id to text file
        if not cursor.rowcount:
            print('No results found for: ' + ead)
            output.write(ead + '\n')
        #if results, write to CSV
        else:
            for row in result:
                print(row)
                with open(csvfile, 'a', encoding='utf-8', newline='') as c:
                    writer = csv.writer(c)
                    writer.writerows([row])
    output.close()
    cursor.close()
Ejemplo n.º 2
0
def get_class_uris():
    cursor = admin.login_db()
    identifier = input('Please enter classification identifier (i.e. YRG): ')
    csvfile = input('Please enter path to output CSV: ')
    cursor.execute("""
    SELECT title
        , identifier
        , description
        , parent_name
        , CONCAT('/repositories/12/classification_terms/', id) AS URI
    FROM classification_term
    WHERE identifier like '%""" + identifier + """%'""")
    result = cursor.fetchall()
    for row in result:
        print(row)
        with open(csvfile, 'a', newline='') as c:
            writer = csv.writer(c)
            writer.writerows([row])
    cursor.close()
Ejemplo n.º 3
0
def get_class_rec_links():
    cursor = admin.login_db()
    identifier = input('Please enter classification identifier (i.e. YRG): ')
    csvfile = input('Please enter path to output CSV: ')
    cursor.execute("""
    SELECT ct.identifier AS classification_identifier
        , ct.title AS classification_title
        , resource.identifier AS resource_identifier
        , resource.title AS resource_title
        , CONCAT('/repositories/12/classification_terms/', ct.id) AS classification_URI
        , CONCAT('/repositories/12/resources', resource.id) AS resource_URI
    FROM classification_term ct
    LEFT JOIN classification_rlshp cr on cr.classification_term_id = ct.id
    LEFT JOIN resource on resource.id = cr.resource_id
    WHERE ct.identifier like '%""" + identifier + """%'""")
    result = cursor.fetchall()
    for row in result:
        print(row)
        with open(csvfile, 'a', newline='') as c:
            writer = csv.writer(c)
            writer.writerows([row])
    cursor.close()
Ejemplo n.º 4
0
def search_by_id():
    cursor = admin.login_db()
    #perhaps change these to be arguments...there are a few other things to fix too.
    repository_num = input('Please enter your repository number: ')
    #create list from ead ids in text file
    outfile = input('Please enter path to identifier list')
    eadlist = open(outfile, 'r')
    eadlisty = eadlist.read().split('\n')
    #sometimes a newline gets stuck in there - this takes care of that
    if eadlisty[-1] == '':
        del eadlisty[-1]
    moveon = input('Please press enter to run query...')
    print(moveon)
    #text file to store eads that don't have notes of the selected type attached
    textfile = input('Please enter path to output text file: ')
    output = open(textfile, 'a')
    #CSV file to store query data
    csvfile = input('Please enter path to output CSV: ')
    #needs headers in output CSV
    for ead in eadlisty:
        print('querying ' + ead)
        cursor.execute("""""")
        result = cursor.fetchall()
        #if no results, write ead id to text file
        if not cursor.rowcount:
            print('No results found for: ' + ead)
            output.write(ead + '\n')
        #if results, write to CSV
        else:
            for row in result:
                print(row)
                with open(csvfile, 'a', encoding='utf-8', newline='') as c:
                    writer = csv.writer(c)
                    writer.writerows([row])
    output.close()
    cursor.close()