Last active
September 12, 2016 19:54
-
-
Save drsnyder/afe5898ab3e05609487cb8527d543d62 to your computer and use it in GitHub Desktop.
Qubole to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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