I'd like to populate a field on existing nodes with an id number from a CSV file. The CSV file contains the full URL of the node e.g. http://www.newcollege.ac.uk/mynode and an id number. There are 283 rows. I've written some code which looks up the node by it's path, returns the node id and then updates the node itself. See example code below.

I'd like to put this in a feeds plugin, but unsure whether this would be a mapper or parser. Can anyone advise?

<?php
$urls
= array(
   
'item-test' => '557',
   
'test' => '200'
);

foreach(
$urls as $path => $cc_id) {
   
$nid = get_nid_by_path($path);
set_career_coach_id($nid, $cc_id);
}




function
get_nid_by_path($path) {
   
$nid = 0;
   
$drupal_path = drupal_lookup_path('source', $path, NULL);
    if (!empty(
$drupal_path)) {
       
$drupal_path = explode('/', $drupal_path);
        if (
count($drupal_path) == 2) {
           
$nid = $drupal_path[1];
        }
    }
    return
$nid;
}

function
set_career_coach_id($nid, $career_coach_id) {
    if (
$nid > 0) {
       
$node = node_load($nid);
        if (!empty(
$node) || $node != null) {
            if (
$node->status == 1) {
               
$node->field_career_coach_course_id['und'][0]['value'] = $career_coach_id;
               
node_save($node);
            } else {
//log that the node isn't published
           
}
        } else {
           
//log that we couldn't load the node
       
}
    }
}
?>