Neatline - error during batch ingest via Ruby

I successfully geocoded my data and created a CSV file using part 1 of the Geocoding for Neatline tutorial (http://www.scholarslab.org/digital-humanities/geocoding-for-neatline-part-i/).

Now I've moved on to part 2 (http://neatline.org/2012/09/12/geocoding-for-neatline-part-ii/), which is where I've run into syntax errors. This is the message I get after plugging in the code adapted from the tutorial:

populate.rb:26: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
[gist id=3307210 file=add_item_snippet.rb]
^
populate.rb:26: syntax error, unexpected tIDENTIFIER, expecting keyword_end
[gist id=3307210 file=add_item_snippet.rb]
^
populate.rb:26: syntax error, unexpected ']', expecting keyword_end
[gist id=3307210 file=add_item_snippet.rb]
^
populate.rb:28: syntax error, unexpected tIDENTIFIER, expecting keyword_end
[gist id=3307210 file=populate.rb]
^
populate.rb:28: syntax error, unexpected ']', expecting keyword_end
[gist id=3307210 file=populate.rb]

Wayne, do you know why I would get these errors? Do I need to treat these gists in a different way in my code? I'm unfamiliar with them.

Thanks!
Brianna

Wayne, or anyone else familiar with Ruby--do you have any idea why I might be receiving these errors? I would appreciate any advice on how to fix this code or an alternate way to batch import geospatial information into Neatline. Thanks!

Hi Brianna,

Take a look at the much better formatted version at http://www.scholarslab.org/digital-humanities/geocoding-for-neatline-part-ii/.

I suspect you've got the braces from the gist in your code, which is telling the ruby interpretor to create an array with invalid syntax. It should actually look like the code here: https://gist.github.com/waynegraham/3307210#file-populate-rb.

Feel free to leave a comment on the post if you run in to problems.

Wayne

Here's the code I was able to make work--I made just a few slight modifications to the code you provided. Hopefully this will help others if they run into a similar issue.

require 'rubygems'
require 'mechanize'
require 'csv'

#code to process CSV points

agent = Mechanize.new {|a|
a.user_agent_alias = 'Windows Mozilla'
}

#code to fill out Omeka forms

page = agent.get('add_your_Neatline_URL_here')
omeka_page = page.form_with(:action => '/admin/users/login') do |form|
form['username'] = 'add_your_username_here'
form['password'] = 'add_your_password_here'
end.submit

# read CSV file

CSV.foreach('./geocoded_
country.csv', :headers => true, :header_converters => :symbol) do |line|
# add logic to fill out form

# click on items
item_page = agent.click(omeka_page.link_with(:text => %r/Items/))
# click on add items
add_item_page = agent.click(item_page.link_with(:text => %r/Add an Item/))

# Add the item to the form

add_item_page.form_with(:method => 'POST') do |item_form|
item_form['public'] = 1
item_form['Elements[50][0][text]'] = line[:address]
# This should really be KML, but it will recognize WKT too.
item_form['Elements[38][0][geo]'] = line[:point]
item_form['Elements[38][0][zoom]'] = 10
item_form['Elements[38][0][mapon]'] = 1
item_form['Elements[38][0][center_lon]'] = line[:lon]
item_form['Elements[38][0][center_lat]'] = line[:lat]
item_form['Elements[38][0][text]'] = "POINT(#{line[:address]})" + '////osm
'
end.submit
$end