Skip to content

Instantly share code, notes, and snippets.

@drsnyder
Last active September 12, 2016 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drsnyder/afe5898ab3e05609487cb8527d543d62 to your computer and use it in GitHub Desktop.
Save drsnyder/afe5898ab3e05609487cb8527d543d62 to your computer and use it in GitHub Desktop.
Qubole to CSV
__author__ = 'minesh'
from optparse import OptionParser
from qds_sdk.commands import *
from io import *
class ResultsFP:
def __init__(self, filename):
self.filename = filename
def write(self, res):
f = open(self.filename, 'a')
f.write(unicode(res))
def downloadresults(commandid):
outputfilename = commandid+'_out.csv'
resultsfp = ResultsFP(outputfilename)
print "Downloading result for command id: %s" % (commandid)
c = Command.find(commandid)
c.get_results(fp=resultsfp, delim=',', inline=False)
optparser = OptionParser()
optparser.add_option("-t", "--token", dest="token", default="", help="provide your Qubole API Token")
optparser.add_option("-c", "--commandid", dest="commandid", default="", help="provide the command id")
(opts, args) = optparser.parse_args()
if (opts.commandid == None or opts.commandid == '' or opts.token == None or opts.token == ''):
optparser.print_help()
exit(1)
Qubole.configure(api_token=opts.token)
downloadresults(opts.commandid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment