Using ipaddr.py with Google Refine?

29 views
Skip to first unread message

Eric Jarvies

unread,
Jun 15, 2012, 2:12:39 AM6/15/12
to ipaddr...@googlegroups.com
Hello,

Perhaps someone here has experience using ipaddr.py with Google Refine?

I have some tables with columns containing IP addresses in Decimal format, and would like to convert them to a more user friendly, human readable Dotted Quad format.   I was unable to accomplish this using Google Refine itself(although I imagine it is possible providing one knows what they are doing, i.e.- not me).  So, another Refine user suggested I try ipaddr.py, and I did.  I downloaded ipaddr.py and placed it into my google Refine.app folder(Contents > Resources > webapp > extensions > jython > module > MOD-INF > lib > jython), restarted Google Refine, and then attempted to use ipaddr.py by creating a Custom text facet and selecting Jython as the language flavor, and then added the following expression:
import ipaddr
return ipaddr.IPv4Interface

But no dice... did not work.  If anyone could offer some advice... it would be much appreciated.  

Thank you,

Eric Jarvies


Peter Moody

unread,
Jun 15, 2012, 2:39:06 AM6/15/12
to Eric Jarvies, ipaddr...@googlegroups.com
Hi Eric,

I don't about google refine, so I can't offer you any specific support
with that. what's the actual error you're getting when you try to
convert the decimal address to a dotted-quade (this is an ipv4 address
you're talking about, right?)

Cheers,
peter
--
Peter Moody      Google    1.650.253.7306
Security Engineer  pgp:0xC3410038

Eric Jarvies

unread,
Jun 15, 2012, 2:46:20 AM6/15/12
to ipaddr...@googlegroups.com, Eric Jarvies
Peter,

I simply get Error:null returned to each of the records(as seen in the attached image):
Screen Shot 2012-06-15 at 12.44.13 AM.jpg

Peter Moody

unread,
Jun 15, 2012, 2:51:31 AM6/15/12
to Eric Jarvies, ipaddr...@googlegroups.com
it *seems* to interpret that as one line (?) try putting a semi-colon
after 'import ipaddr'?

alternatively, do you know what type of object refine is looking for?
you're returning an object of ipaddr.IPv4Interface, maybe you need to
return str(ipaddr.IPv4Interface(foo)) ?

these are just guesses. without knowing more about how google refine
interacts with python, I can't give much more.

Eric Jarvies

unread,
Jun 15, 2012, 3:14:47 AM6/15/12
to ipaddr...@googlegroups.com, Eric Jarvies
Peter,

Thanks for your help.  However, just a few moments ago I was given a Refine-specific solution to my problem, so I do not need to use ipaddr.py to accomplish the task.  Paul, over at the Refine list, provided the solution.  Not sure if anyone else will venture over here in need of a similar solution, but I will go ahead and post the solution below just in case, and os this thread is not entirely a waste of space:

-make sure the column is numerical(e.g.- Edit cells > Common transformations > To number)
-Edit cells > transform (or Add column > Add column based on this column  or  Facet > Custom text facet) and paste the following into the expression field;
floor((value/256/256/256)%256) +"."+ 
floor((value/256/256)%256) +"."+
floor((value/256)%256) +"."+ 
floor(value%256)

And that's it!

Thanks again.

Eric
Reply all
Reply to author
Forward
0 new messages