Created
April 2, 2015 19:37
-
-
Save josuebrunel/fc8882b8ebfc09d266ee to your computer and use it in GitHub Desktop.
This file contains 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
import pdb | |
import sys | |
import cmd | |
import argparse | |
from lokingyql import LokingYQL | |
class ExecuteAction(argparse.Action): | |
def __call__(self, parser, namespace, value, option_string=None): | |
pdb.set_trace() | |
yql = LokingYQL(community=True) | |
response = yql.rawQuery(value) | |
if not response.status_code == 200: | |
print(response.content) | |
sys.exit(1) | |
print(response.json()) | |
sys.exit(0) | |
class ShellAction(argparse.Action): | |
def __call__(self, parser, namespace, value, option_string=None): | |
pass | |
class TableAction(argparse.Action): | |
def __call__(self, parser, namespace, value, option_string=None): | |
pass | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser("YQL-cli tools") | |
subparsers = parser.add_subparsers(help='commands') | |
execute_parser = subparsers.add_parser('execute', help='Execute an YQL query') | |
execute_parser.add_argument( | |
'execute', | |
action=ExecuteAction, | |
help="Execute an YQL query" | |
) | |
execute_parser.add_argument( | |
'--format', | |
default='json', | |
action=ExecuteAction, | |
help="Response format" | |
) | |
shell_parser = subparsers.add_parser('shell', help='Prompt a shell') | |
shell_parser.add_argument( | |
'shell', | |
action=ShellAction, | |
help="SQL like shell" | |
) | |
create_parser = subparsers.add_parser('create', help='Create a YQL table') | |
create_parser.add_argument( | |
'create-table', | |
action=TableAction, | |
help="Create a YQL Table from python file" | |
) | |
args = vars(parser.parse_args()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment