Introducing the Google Command Line Tool
Posted:
Friday, June 18, 2010

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 vimGoogleCL 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

Wow, I've needed this for a while. I've had to write bits and pieces of it myself. Thanks!
ReplyDeleteNot 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).
ReplyDeleteProps for more options though, and also for opening up comments when most Google blogs are closed.
Just create a loop script. then its practically like uploading the folder
DeleteIf you're on a Mac, you can use the Picasa Web Albums Uploader. http://www.google.com/mac/
ReplyDeleteIf you use Lightroom or Aperture, you can get plugins that'll upload to Picasaweb from inside the app.
Nice!
ReplyDeleteAwesome!! Thanks :)
ReplyDeleteLooks nice. Have you ever used goosh.com (the unofficial google shell)? You probably would like it!
ReplyDeleteRuben
@nomical Um.. did you read the example commands at all? What you asked for is exactly what one of the sample commands does.
ReplyDeletewould 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...
ReplyDeleteIt would be nice to see this in the Google Linux repos (http://www.google.com/linuxrepositories/)
ReplyDeleteEffing amazing.
ReplyDeletewow... it's a good news...!!
ReplyDeleteWow!
ReplyDeleteGreat idea!
ReplyDeleteI love it!
ReplyDeleteI love you!! This couldn't be better!!
ReplyDelete@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.:
ReplyDeletedef 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')
excellent !
ReplyDeleteShouldn'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".
ReplyDeleteLOVE this.
ReplyDeleteEmbed android-scripting in your Android Market app.
ReplyDeleteRun GoogleCL on top of it and you've got something!
I don't know what it is -- but it's something.
You might want to link to gdata from http://code.google.com/p/gdata-python-client/downloads/list
ReplyDeleteAwesome
ReplyDelete@Roadnottaken
ReplyDeleteMake 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
Ooh, I hope it's not April 1 today. *calendar check* Wow, nope!
ReplyDeleteReally nice!
There goes my Friday evening...
This will have enormous commercial applications.
ReplyDeleteSuperb! CLI FTW!
ReplyDeleteIs there any plan to add Google Voice support?
ReplyDeleteThis google commandline tool is very useful! Thank you for pointing it out.
ReplyDelete@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.
Not using it until I can easy_install it.
ReplyDeleteIs it possible to export reports from Google Analytics?
ReplyDeleteRoadnottaken, 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.
ReplyDeleteWhile 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...
ReplyDeleteeasy_install should work now. please file an issue if you have trouble.
ReplyDeletehttp://code.google.com/p/googlecl/wiki/SystemRequirements
@coldacid
ReplyDeleteThat's what a .deb is for (providing you're on a Debian based system)
How to run this CL on an Android phone?
ReplyDeletewait..so I can edit a Google Doc from the command line, but there is still no proper means of editing it on Android?
ReplyDeleteAnother failure
ReplyDeletewaste of time and prettty useless
Awesome! Was just looking the other day for way to upload images easily to picasa
ReplyDeleteIt seems like linux :) good work
ReplyDeleteGoogle tasks interface pleez
ReplyDeleteCan you make it work with cygwin?
ReplyDeleteKinda geeky for an ordinary consumer.
ReplyDeletehemm 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
ReplyDeleteAwesome I'll give it a try on Fedora 12 box.
ReplyDeleteDammit... too bad I just abandoned blogger because it no longer supports FTP publishing.
ReplyDeleteDammit... too bad I just abandoned blogger because it no longer supports FTP publishing. Oh well.
ReplyDeleteWonderful, I can now script my pics syncs and fast up load blogs.
ReplyDeleteThis is not too geeky. It is handy and fast. And saves much of the browser overhead for embedded applications.
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.
ReplyDeleteHello weekend :D
@ Brian Herman:
ReplyDeleteShould 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.
Well this look exactly like Goosh.org, the only difference is that the author allowed us using Google by command line since 2008.
ReplyDeleteAren't you a bit later for this?
I hope that this will be extended (with the possible necessity of a fork) to work with more video/photo services.
ReplyDeleteWOW i love that....
ReplyDeletecan we have the command line to read gmail too/ ?
i missed the console mode display =P
Amazing :D
ReplyDeleteTremendous!
ReplyDeleteIt's a logical next step to desktop-web integration. No, better to say it's a leap!
How fast new APIs will be added? How full will be the pallette of supported Google APIs?
ReplyDeleteActually, only GData-based. What about the long-term perspective?
Sweet!
ReplyDeleteit 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
ReplyDeleteI love it!
ReplyDeleteAbsolutely aweable :)
ReplyDeleteI haven't started with python yet, but will surely do it. Thanks to team.
ReplyDeletePhotoHand:
ReplyDeleteWell then let the geeks have our shiny new toy! Geeks are a perfectly valid niche.
This is great. Not only because I find it useful but also for the blind people.
ReplyDeleteCool, geeky, and practical.
ReplyDeleteWish I could do this in windows. =P
ReplyDeletebtw in an ubuntu lucid, trying to do "google docs edit ..." will give you
ReplyDelete"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
Cool!
ReplyDeleteCool!
ReplyDeleteThis is very nice, but it would be much more useful to me, if GoogleCL could use a different character set than UTF-8.
ReplyDeleteWorks fine under Mac OS X 10.6 with the system default python :)
ReplyDelete^5 Google. :)
How about a better name, like gsh gosh, gush, goosh, gython, guython, galthon, goothon. Or all those already taken?
ReplyDeleteI'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:
ReplyDeleteLoading 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?
Well, that's really something!
ReplyDeleteHow 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?
Muy buena idea.
ReplyDelete@Jake Kelly: you can still of course do e.g.
ReplyDeletecat Desktop/post.txt | google blogger post --blog "helloes"
by the way, useless use of cat detected:
google blogger post --blog foo < Desktop/post.txt
This is just awesome. :-D
ReplyDeleteSweet!
ReplyDeleteAre 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.
This is so awesome.
ReplyDeleteVery very nice! Seems like the only company that can do real innovation, is Google.
ReplyDeleteNow if only we could get a google-plugin for {a,i}spell in LyX 2.0 ;)
Is it possible to use xml.etree.cElementTree (python 2.5+) instead of ElementTree?
ReplyDeleteAnother vote for google tasks please!
ReplyDeleteIt'd be great to get these to Debian and other repositories, but why not put them on the Google repos for a start?
ReplyDeleteAwesome! 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!
ReplyDeleteCool! tnQ
ReplyDeleteKeep growing Mates.. Awesome work.. Expected it to come some time back..
ReplyDeleteStill we need some improvement i guess...
sweet!! and I just spent a couple hours figuring out how to use wget to get my googledocs.
ReplyDeleteviva la google!!
Big step to avoid daily and repetive clickclick. Now I want a real shell at GAE.
ReplyDeleteNo love for the people behind a proxy :(
ReplyDeleteThis is all full of win. I hope that Google Voice support comes very soon.
ReplyDeleteI'd love to be able to: google voice text 5555555555 "Win!"
GOOGLE CL AND GMAIL:
ReplyDeleteHow 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?
Did you know that GoogleCL has supported 6 Google services such as Blogger, Picasa Web, YouTube, Gmail Contact, Google Docs and Google Calendar?
ReplyDeleteIntroducing the Google Command Line Tool.. thanks for sharing....
ReplyDeleteI tried to list picasa albums:
ReplyDelete$google picasa list-albums
The following python error was spitted out:
Traceback (most recent call last):
File "/usr/bin/google", line 536, in
main()
File "/usr/bin/google", line 530, in main
run_once(options, args)
File "/usr/bin/google", line 371, in run_once
token_valid = client.IsTokenValid()
File "/usr/lib/pymodules/python2.6/googlecl/picasa/service.py", line 218, in is_token_valid
return googlecl.service.BaseServiceCL.IsTokenValid(self, test_uri)
File "/usr/lib/pymodules/python2.6/googlecl/service.py", line 257, in is_token_valid
self.Get(test_uri)
File "/usr/lib/pymodules/python2.6/gdata/service.py", line 988, in Get
feed = gdata.GDataFeedFromString(result_body)
File "/usr/lib/pymodules/python2.6/gdata/__init__.py", line 464, in GDataFeedFromString
return atom.CreateClassFromXMLString(GDataFeed, xml_string)
File "/usr/lib/pymodules/python2.6/atom/__init__.py", line 96, in CreateClassFromXMLString
tree = ElementTree.fromstring(xml_string)
File "", line 86, in XML
SyntaxError: no element found: line 1, column 0
Any hope for a google voice plugin? I'm wanting to have my gv call my COO when a ping-test fails to our gateway. I already have an automated email / text but dude is pretty old school and wants a frickin call...
ReplyDeleteit's slow in my machine. prefer Prism instead
ReplyDeleteExcellent :) great idea.
ReplyDeleteit has refused for a new blogger. What is it?
ReplyDeleteso cool
ReplyDeleteNice. I can grep an entry, which is very useful.
ReplyDeleteHey guys,
ReplyDeleteAn old thread that I found today because I was getting this error.
gdata.youtube.service.YouTubeError: {'status': 401, 'body': 'Unknown authorization header', 'reason': 'Unauthorized'}
I just re-tried it a few times and it failed, then left it for an hour or so and re-tried and blam!
Worked fine.
So seems to be a timeout.
My video was close to 4GB (1 hour)...
Hope this helps someone else
Cheers
Tim
I simply love this feature! GOOGLE ROCKS!
ReplyDeleteFantastic tool. Very useful for linux command line people. Thanks
ReplyDeleteThank you.
ReplyDeleteGreat advice thanks for sharing
ReplyDeleteHow can I change user name ?
ReplyDelete