Introducing the Google Command Line Tool

Friday, June 18, 2010 | 8:55 AM

Labels: ,


Ever wanted to upload a folder full of photos to Picasa from a command prompt? We did, a lot, last summer. It made us want to say:

$ google picasa create --title "My album" ~/Photos/vacation/*.jpg

So we wrote a program to do that, and a whole lot more.

GoogleCL is a command-line utility that provides access to various Google services. It streamlines tasks such as posting to a Blogger blog, adding events to Calendar, or editing documents on Google Docs.

For example:

$ google blogger post --blog "My blog" --tags "python, googlecl, development" my_post.html
$ google calendar add "Lunch with Jason tomorrow at noon"
$ google docs edit --title "Shopping list" --editor vim

GoogleCL is a pure Python application that uses the Python gdata libraries to make Google Data API calls from the command line.

Read more at the GoogleCL project page, or jump right to the examples. Along with a standard tarball, we have a .deb package ready for download, and hope to have it included in Debian and Ubuntu repositories in time for their next releases. We're adding features all the time, so check in frequently. Or better yet, contribute.

GoogleCL brings cloud computing to your fingertips, literally!

By Jason Holt, Street View Team and Tom Miller, former Street View Intern

90 comments:

Firoze said...

Wow, I've needed this for a while. I've had to write bits and pieces of it myself. Thanks!

nomical said...

Not really. I don't know how to program and don't care to start. Wish we could upload a folder to Picasa right now as opposed to individually uploading each item (if we don't have Picasa desktop).

Props for more options though, and also for opening up comments when most Google blogs are closed.

MarkDalrymple said...

If you're on a Mac, you can use the Picasa Web Albums Uploader. http://www.google.com/mac/

If you use Lightroom or Aperture, you can get plugins that'll upload to Picasaweb from inside the app.

wugunz said...

Nice!

Shantanu said...

Awesome!! Thanks :)

RBerenguel said...

Looks nice. Have you ever used goosh.com (the unofficial google shell)? You probably would like it!

Ruben

Geoff said...

@nomical Um.. did you read the example commands at all? What you asked for is exactly what one of the sample commands does.

Roadnottaken said...

would be great if you could also do standard google web-searches via the CL, and presumably get a list of plain-text results back. more-often than not i don't even need to follow the result links, the summary text usually tells me what I want...

steven said...

It would be nice to see this in the Google Linux repos (http://www.google.com/linuxrepositories/)

Schitso said...

Effing amazing.

simukti.info said...

wow... it's a good news...!!

eternal1 said...

Wow!

Devin said...

Great idea!

alienz said...

I love it!

Fisa said...

I love you!! This couldn't be better!!

Dan said...

@RoadNotTaken, this python script will do that for you. If you call the function, it will search for the string contents of arg and print the first blurb. To access more than the first result, change results[0] to some sort of loop.:

def execute(arg = ''):
# Requires simplejson module for AJAX search
# from:http://pypi.python.org/pypi/simplejson
# Example code found at: http://dcortesi.com/
import urllib
import simplejson
import re
import unicodedata
if arg == '':
return 'Error: No search string.'
query = urllib.urlencode({'q' : arg})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (query)
search_results = urllib.urlopen(url)
json = simplejson.loads(search_results.read())
results = json['responseData']['results']
try:
ret = re.sub(r'<[^>]*?>', '', results[0]['content']) # Strips HTML formatting
except:
return "There was an error parsing data. Please try again."
ret = re.sub(r'&[^ ]*?;', '', ret) # Strips HTML special characters (ie. " )
return unicodedata.normalize('NFKD', unicode(ret, "utf-8")).encode('ascii','ignore')
#return unicodedata.normalize('NFKD', ret).encode('ascii','ignore')

Jim Ramia said...

excellent !

Jeff Kelley said...

Shouldn't they be split up into several command-line utilities? For instance, "picasa" instead of "google picasa"? That would allow crazy things, like "cat Desktop/post.txt | blogger".

webguy said...

LOVE this.

Timothy Lee Russell said...

Embed android-scripting in your Android Market app.

Run GoogleCL on top of it and you've got something!

I don't know what it is -- but it's something.

James Salsman said...

You might want to link to gdata from http://code.google.com/p/gdata-python-client/downloads/list

Sheldon said...

Awesome

Malicious Monkey said...

@Roadnottaken

Make sure you have w3m installed, and then put the following in a file called "search" (or whatever you like):

#!/bin/bash
wget http://www.google.com/search?q="$*" -U "FakeBrowser 9000" -O - | w3m -T text/html -dump

Then do "chmod a+x search". Now you can say things like:
./search foo bar baz

Shane Conder said...

Ooh, I hope it's not April 1 today. *calendar check* Wow, nope!

Really nice!

There goes my Friday evening...

Ing. Juan Ignacio Zamora M, MSc. said...

This will have enormous commercial applications.

Kris J said...

Superb! CLI FTW!

GoodDamon said...

Is there any plan to add Google Voice support?

Sanjaya Yogi said...

This google commandline tool is very useful! Thank you for pointing it out.


@Roadnottaken:
To scrape an individual web page:

Create a file:

nano scrape

#!/bin/sh
wget $1 -U "FakeBrowser 9000" -O - | w3m -T text/html -dump > $2

chmod a+x scrape

To use:

scrape arg1 (a URL) arg2 (output to a file)

Example:
scrape dcortesi.com/ dcortesi

cat dcortesi

Gives you a text dump of the web page.

coldacid said...

Not using it until I can easy_install it.

eventides said...

Is it possible to export reports from Google Analytics?

Anonymous Coward said...

Roadnottaken, you have been able to do this forever with the console browsers of links, lynx, w3c, wget or curl. The last two need you to be a little creative (knowing sed and awk helps) but the first 3 just need you to read the man page and know how to search in google from an url ( http://www.google.com/search?q=puppy%20dogs ). You could wrap the final result into a bash script though I would use php for urlencode (to make sure items like space are replaced with %20) which can also be run on the command line and hence inside a bash script as well.

joris said...

While it's an awesome idea, it really needs support for search and mail before I can call it handy. I mean, of all Google services, aren't those two the most used? and the easiest accessible from commandline, too? I love my commandline, but for images, video, docs, ... I prefer some sort of GUI with a WYSIWYG thing going on...

jholt said...

easy_install should work now. please file an issue if you have trouble.

http://code.google.com/p/googlecl/wiki/SystemRequirements

Jorick said...

@coldacid

That's what a .deb is for (providing you're on a Debian based system)

Sam Liang said...

How to run this CL on an Android phone?

karnage said...

wait..so I can edit a Google Doc from the command line, but there is still no proper means of editing it on Android?

Dhiraj said...

Another failure
waste of time and prettty useless

Max Thrun said...

Awesome! Was just looking the other day for way to upload images easily to picasa

Bilgee said...

It seems like linux :) good work

ndepalma said...

Google tasks interface pleez

Brian Herman said...

Can you make it work with cygwin?

PhotoHand said...

Kinda geeky for an ordinary consumer.

najmi said...

hemm for google calendar how exactly i can specify the date that I want to put task. using$ google calendar add "Matlab training @ Sheraton" --date 2010 -06-22 put the date to TODAY ... put this in the feature bugrequest. TQ

asraikhn said...

Awesome I'll give it a try on Fedora 12 box.

Anthony Fejes said...

Dammit... too bad I just abandoned blogger because it no longer supports FTP publishing.

Anthony Fejes said...

Dammit... too bad I just abandoned blogger because it no longer supports FTP publishing. Oh well.

Socially Active said...

Wonderful, I can now script my pics syncs and fast up load blogs.

This is not too geeky. It is handy and fast. And saves much of the browser overhead for embedded applications.

Daniel H said...

Sweet bash, thanks! If only i had Wifi or 3G on my e1000d i could make pictures appear online as soon as i take them.

Hello weekend :D

Sharpie said...

@ Brian Herman:

Should work on any platform for which you have python installed. It is already in the cheese shop, I was able to get it via:

pip install gdata
pip install googlecl

Of course, you can use easy_install instead of pip if you like.

seoer said...

Well this look exactly like Goosh.org, the only difference is that the author allowed us using Google by command line since 2008.

Aren't you a bit later for this?

thegzeus said...

I hope that this will be extended (with the possible necessity of a fork) to work with more video/photo services.

karlili said...

WOW i love that....
can we have the command line to read gmail too/ ?
i missed the console mode display =P

nXqd said...

Amazing :D

jaCoder said...

Tremendous!
It's a logical next step to desktop-web integration. No, better to say it's a leap!

jaCoder said...

How fast new APIs will be added? How full will be the pallette of supported Google APIs?
Actually, only GData-based. What about the long-term perspective?

Lord Juan said...

Sweet!

Tomas said...

it seems great, i hope you will add support for analytics and adwords and search of course. An i hope it will be possible to create some complex queries with combination of those services. And it could be online service btw - e.g. i think it should not be a problem to program it so you could use standard google.com input box

coirius said...

I love it!

scavenger said...

Absolutely aweable :)

Shekhar Sahu said...

I haven't started with python yet, but will surely do it. Thanks to team.

Mackenzie said...

PhotoHand:
Well then let the geeks have our shiny new toy! Geeks are a perfectly valid niche.

jarko_ said...

This is great. Not only because I find it useful but also for the blind people.

NicolasJEngler said...

Cool, geeky, and practical.

Jasper Winkel said...

Wish I could do this in windows. =P

JuanJo said...

btw in an ubuntu lucid, trying to do "google docs edit ..." will give you
"Editing documents is not supported for gdata-python-client < 2.0"


This is because ubuntu repos only provide python-gdata 1.2.4, but you can upgrade it by downloading and installing debian squeeze .deb package with:


$ wget https://ftp.ch.debian.org/debian/pool/main/p/python-gdata/python-gdata_2.0.8-1.1_all.deb

$ sudo dpkg -i python-gdata_2.0.8-1.1_all.deb

sojourner712 said...

Cool!

sojourner712 said...

Cool!

shj said...

This is very nice, but it would be much more useful to me, if GoogleCL could use a different character set than UTF-8.

Tor Nilsen said...

Works fine under Mac OS X 10.6 with the system default python :)

^5 Google. :)

yottzumm said...

How about a better name, like gsh gosh, gush, goosh, gython, guython, galthon, goothon. Or all those already taken?

The said...

I've been typing to upload a video to youtube using this. It works on tiny test videos, but when I try it on the 395MB video I want to upload, I always get an error:

Loading DSCN0882.AVI
Traceback (most recent call last):
File "/usr/bin/google", line 448, in
main()
File "/usr/bin/google", line 442, in main
run_once(options, args)
File "/usr/bin/google", line 337, in run_once
task.run(client, options, args)
File "/usr/lib/pymodules/python2.6/googlecl/youtube/service.py", line 217, in _run_post
tags=options.tags, category=options.category)
File "/usr/lib/pymodules/python2.6/googlecl/youtube/service.py", line 129, in post_videos
self.InsertVideoEntry(video_entry, path)
File "/usr/lib/pymodules/python2.6/gdata/youtube/service.py", line 653, in InsertVideoEntry
raise YouTubeError(e.args[0])
gdata.youtube.service.YouTubeError: {'status': 401, 'body': 'Unknown authorization header', 'reason': 'Unauthorized'}

What gives?

Werner said...

Well, that's really something!

How about uploading a whole folder to Google Web Space?
How about synchronising this folder with the corresponding one on the harddrive?
Is there an code?

jecaestevez said...

Muy buena idea.

Rasmus S said...

@Jake Kelly: you can still of course do e.g.
cat Desktop/post.txt | google blogger post --blog "helloes"

by the way, useless use of cat detected:
google blogger post --blog foo < Desktop/post.txt

Phil Crump said...

This is just awesome. :-D

Nicolas_Raoul said...

Sweet!
Are there plans to have this tool for tasks?
At least: list tasks, add a task, mark a taskas done... does not seem extremely hard to do.

4v4l0n42 said...

This is so awesome.

Mark R said...

Very very nice! Seems like the only company that can do real innovation, is Google.

Now if only we could get a google-plugin for {a,i}spell in LyX 2.0 ;)

शंतनू said...

Is it possible to use xml.etree.cElementTree (python 2.5+) instead of ElementTree?

Hunter said...

Another vote for google tasks please!

XTL said...

It'd be great to get these to Debian and other repositories, but why not put them on the Google repos for a start?

pat5star said...

Awesome! Exactly what I've wanted for awhile and this is also the push I've needed that will have me take another look at picasa to replace digikam with again. Thank you Google!

Mrt said...

Cool! tnQ

ankit anand said...

Keep growing Mates.. Awesome work.. Expected it to come some time back..
Still we need some improvement i guess...

smyth_rj said...

sweet!! and I just spent a couple hours figuring out how to use wget to get my googledocs.
viva la google!!

novi said...

Big step to avoid daily and repetive clickclick. Now I want a real shell at GAE.

can said...

No love for the people behind a proxy :(

Maxo said...

This is all full of win. I hope that Google Voice support comes very soon.
I'd love to be able to: google voice text 5555555555 "Win!"

Pay said...

GOOGLE CL AND GMAIL:

How about using Google CL to command the functions of a Gmail box. Compose a Gmail, Send a Gmail, Reply to Gmail, Search Gmail. Sound interesting? Any time lines for availability?

Kells said...

Did you know that GoogleCL has supported 6 Google services such as Blogger, Picasa Web, YouTube, Gmail Contact, Google Docs and Google Calendar?