• Poor Man’s Conversion Using Google Drive API

    by  • May 19, 2013 • Uncategorized

    I lost count of how many times I have used Google Drive to convert a document to one format and download it as another. This generally means firing up a browser, logging into a random Google account, uploading the document, re-downloading it and then deleting to save space. Sure, there are utilities to do conversions between one file format to another, but some of them charge money and others don’t offer a Python-friendly interface.

    Screen Shot 2013-05-19 at 5.10.12 PM

    Fortunately, Google offers a well-documented API for their drive service. The entire flow I mentioned above is easily implemented in three calls, but I needed a more dynamic solution. Here is a link to a function I wrote to take in your drive instance, a file, out type and out file and then convert it using the methodology I outlined above. As a convenience, I return a file handle for those who want to use the file without calling open again. Google limits API calls to 10,000 requests a day, but unless you are doing some mass-conversion job, I think this solution works out well. Keep in mind, to make all of this work, you need to register an application to interact with your drive and then approve the Oauth.

     

    About