#! /usr/bin/perl

$baseURL = "https://okapi-drew.folio.ebsco.com";
$jsonHeader = "Content-type: application/json";
$xOkapiToken = `cat okapi-token.txt`;

use JSON;

@allBannerInfo = `cat allBannerInfo.txt`;

foreach $row (@allBannerInfo) {
    $countRows++;
    @fields = split(/\|/,$row);
    if ($fields[19] eq "Y") {
        $countStudents++;
        $barcode = $fields[0];
        $userJSON = `curl -s -w '\n' -X GET -G -H '$jsonHeader' -H '$xOkapiToken' $baseURL/users?query=barcode=="$barcode"`;
        if ($userJSON =~ /"totalRecords": 0/) {
            $do = "nothing";
        } else {
            $countUpdates++;
            $do = "put";
            $studentHash = decode_json $userJSON;
            for ( @{$studentHash->{users}} ) {
                $userId = $_->{'id'};
                $userJSON =~ s/{\n  "users": \[\n//;
                ($data,$moreDreck) = split(/\],\n  "totalRecords"/,$userJSON);
                $data =~ s/active":false/active":true/;
                $data =~ s/expirationDate":"\d\d\d\d-\d\d-\d\d/expirationDate":"2025-07-15/;
                $data =~ s/'/'\\''/g;
                $put = `curl -s -w '\n' -X PUT -H '$jsonHeader' -H '$xOkapiToken' -d '$data' $baseURL/users/$userId`;
            }
        }
        print "$countRows $countStudents $countUpdates\n";
    }
}

  • No labels
Write a comment…