def process(args):
    item_file = handle_files.readFileFromLocal(args.itemFile) 
    
    operation = args.operation
    output_dir = args.outputDir
    
    # get a token
    scope = ['WorldCatMetadataAPI']
    try:
        oauth_session = make_requests.createOAuthSession(config, scope)
    
        config.update({"oauth-session": oauth_session})
        processConfig = config
        csv_read = handle_files.loadCSV(item_file) 
        
        if operation == "getCurrentOCLCNumbers":
            csv_read = process_data.retrieveCurrentOCLCNumbers(processConfig, csv_read)
        elif operation == "retrieveMergedOCLCNumbers":
            csv_read = process_data.retrieveMergedOCLCNumbers(processConfig, csv_read)    
        elif operation == "setHoldingsbyOCLCNumber":                
            csv_read = process_data.setHoldingsbyOCLCNumber(processConfig, csv_read)   
        elif operation == "deleteHoldingsbyOCLCNumber":
            csv_read = process_data.deleteHoldingsbyOCLCNumber(processConfig, csv_read)
        elif operation == "addLBDs":
            csv_read = process_data.addLBDs(processConfig, csv_read)            
    
        return handle_files.saveFileLocal(csv_read, output_dir)

    except BaseException as err:
        result = 'no access token ' + str(err)
        return result   
def mockOAuthSession(requests_mock, getTestConfig):
    requests_mock.register_uri('POST',
                               getTestConfig.get('token_url'),
                               status_code=200,
                               json=oauth_response)
    oauth_session = make_requests.createOAuthSession(getTestConfig, 'wcapi')
    return oauth_session
Esempio n. 3
0
def test_createOAuthSession(requests_mock, getTestConfig):
    #?grant_type=client_credentials&scope=wcapi
    requests_mock.register_uri('POST',
                               'https://oauth.oclc.org/token',
                               status_code=200,
                               json=oauth_response)
    oauth_session = make_requests.createOAuthSession(getTestConfig, 'wcapi')
    assert type(oauth_session) is OAuth2Session
    assert oauth_session.access_token == 'tk_12345'
def process(args):
    with open(config_file, 'r') as stream:
        config = yaml.safe_load(stream)
    item_file = handle_files.readFileFromLocal(args.itemFile)

    operation = args.operation
    output_dir = args.outputDir

    try:
        oauth_session = make_requests.createOAuthSession(
            config, [config.read('scope')])

        config.update({"oauth-session": oauth_session})
        processConfig = config
        csv_read = handle_files.loadCSV(item_file)
        if operation == "retrieveAllInstitutionRetentions":
            results = []
            for index, row in csv_read.iterrows():
                csv_read_institution = process_data.retrieveAllInstitutionRetentions(
                    processConfig, row['symbol'])
                result = handle_files.saveFileLocal(csv_read_institution,
                                                    output_dir)
                results.append(row['symbol'] + ": " + result)

            return ",".join(results)
        else:
            if operation == "retrieveMergedOCLCNumbers":
                csv_read = process_data.retrieveMergedOCLCNumbers(
                    processConfig, csv_read)
            elif operation == "retrieveHoldingsByOCLCNumber":
                if hasattr(args, 'heldBy'):
                    heldBy = args.heldBy
                elif hasattr(args, 'heldByGroup'):
                    heldByGroup = args.heldByGroup
                csv_read = process_data.retrieveHoldingsByOCLCNumber(
                    processConfig, csv_read, heldByGroup, heldBy)

            elif operation == "retrieveSPByOCLCNumber":
                csv_read = process_data.retrieveSPByOCLCNumber(
                    processConfig, csv_read, heldByGroup, heldInState)
                if hasattr(args, 'heldByGroup'):
                    heldByGroup = args.heldByGroup
                elif hasattr(args, 'heldInState'):
                    heldInState = args.heldInState
            elif operation == "retrieveInstitutionRetentionsbyOCLCNumber":
                heldBy = args.heldBy
                csv_read = process_data.retrieveInstitutionRetentionsbyOCLCNumber(
                    processConfig, csv_read, heldBy)

            return handle_files.saveFileLocal(csv_read, output_dir)

    except BaseException as err:
        result = 'no access token ' + str(err)
        return result
Esempio n. 5
0
import yaml
import os
from src import handle_files, process_data, make_requests
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

# load key/secret config info
# read a configuration file
with open("config.yml", 'r') as stream:
    config = yaml.safe_load(stream)

# get a token
oauth_session = make_requests.createOAuthSession(config,
                                                 [config.read('scope')])

processConfig = config.update({"oauth-session": oauth_session})


def getMergedOCLCNumbers(event, context):
    item_file = handle_files.readFilesFromBucket(event)
    csv_read = handle_files.loadCSV(item_file)
    csv_read = process_data.retrieveMergedOCLCNumbers(processConfig, csv_read)
    handle_files.saveFileToBucket(fileInfo['bucket'],
                                  fileInfo['key'] + "_updated", csv_read)


## file contains OCLC Numbers
def checkHoldingsByOCLCNumber(event, context):
    item_file = handle_files.readFilesFromBucket(event)
    csv_read = handle_files.loadCSV(item_file)
    csv_read = process_data.retrieveHoldingsByOCLCNumber(
        processConfig, csv_read)
import yaml
import os
from src import handle_files, process_data, make_requests
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

# load key/secret config info
# read a configuration file
with open("config.yml", 'r') as stream:
    config = yaml.safe_load(stream)

# get a token
scope = ['WorldCatMetadataAPI']
oauth_session = make_requests.createOAuthSession(config, scope)

processConfig = config.update({"oauth-session": oauth_session})


def getCurrentOCLCNumbers(event, context):
    item_file = handle_files.readFilesFromBucket(event)
    csv_read = handle_files.loadCSV(item_file)
    csv_read = process_data.retrieveCurrentOCLCNumbers(processConfig, csv_read)
    handle_files.saveFileToBucket(fileInfo['bucket'],
                                  fileInfo['key'] + "_updated", csv_read)

    return saveFile(bucket, key + "_updated", csv_read)


def getMergedOCLCNumbers(event, context):
    item_file = handle_files.readFilesFromBucket(event)
    csv_read = handle_files.loadCSV(item_file)
    csv_read = process_data.retrieveMergedOCLCNumbers(processConfig, csv_read)