Query your Google Drive with a Go command-line tool

Programming Snapshot – Google Drive Search Tool

© Lead Image © Alphaspirit, 123RF.com

© Lead Image © Alphaspirit, 123RF.com

Article from Issue 279/2024
Author(s):

To help him check his Google Drive files with three different pattern matchers, Mike builds a command-line tool in Go to maintain a meta cache.

My digital library of scanned paper books is stashed away as PDF files in an account on Google Drive. So far, Google has done an exemplary job of keeping my data available, but I just can't make friends with their search interface. In typical Google style, the browser shows you a search field that can be used to quickly browse the indexed full text of all the files in all the folders. However, getting a simple answer to the question of whether I already have a certain book in my archive is more difficult. To do this, I have to select the file names only and restrict the search to specific folders.

Fortunately, though, Google provides an intuitive API [1] to access user data in the Google Drive cloud. For quick checks, a command-line tool comes in handy. While we're at it, it's worth taking a trip into the world of pattern matchers, of which there are, as we all know, a wide variety. For example, the shell relies on a glob mechanism for matching, while programming languages typically rely on regular expressions (regexes). And sometimes, a simple string matcher like the grep command is the most practical solution.

Parallel Regex Worlds

If you type ls *.jpg on the command line, you expect the shell's match mechanism to find all files with a .jpg extension. This pattern matching is fundamentally different from Perl Compatible Regular Expressions (PCRE) [2] used in programming languages. Funnily enough, they originated with the Perl scripting language many years ago, but all modern languages from Python to Java and C++ to Go support them as well.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Perl: Google Drive

    Armed with a Chinese guillotine and a scanner with an automatic document feeder, Mike Schilli gives his books some special treatment, courtesy of Google Drive, which offers 5GB of storage space – room enough to start an online PDF collection.

  • Book Collector

    Mike Schilli does not put books on the shelf; instead, he scans them and saves the PDFs in Google Drive. A command-line Go program then rummages through the digitized books and downloads them as required.

  • Perl – Tagging e-Books in Evernote

    Google Drive lacks a mechanism for tagging files, so we look at two APIs that scripts can use to store metadata on Evernote, allowing searches of e-books by category or property.

  • Perl – Security Snapshots

    When the Perlmeister is on the road, he likes to know what's going on at home. Armed with just two scripts, he draws on the Tumblr API to store snapshots cyclically from his home security camera.

  • Perl: Tricks with Vim

    The Vim editor has any number of tricks for helping you avoid unnecessary typing. In this month’s article, we look at some effort-saving Vim techniques for Perl hackers.

comments powered by Disqus