from urllib import urlencode import sys import auth from ox.cache import read_url, cache_timeout from ox import find_string, find_re,net """ Two arguments: text_inp: str/list of str. Input text for which tonal data is to be retrieved. req_index: Request type for the api command 0- tonalize 1- tonalize_detailed 2- tonalize_multiple 3- flag_response """ def set_initial_stuff(): """ Just to setup the initial common variables """ global headers, base_url,req_type try: headers = {} headers.update(net.DEFAULT_HEADERS) headers.update({'AUTHENTICATION':auth.get('lymbix_api_key'),'Accept':'application/json','VERSION':'2.2'}) base_url = 'http://api.lymbix.com/' req_type = ['tonalize','tonalize_detailed','tonalize_multiple','flag_response'] except Exception,e: raise e def get_lymbix_tonalize(text_inp,timeout = cache_timeout): """ """ data = {'article':text_inp} print data, base_url+req_type[0], headers content = read_url(base_url+req_type[0],urlencode(data),headers,timeout, unicode=True) return content def get_lymbix_tonalize_multiple(text_inp,timeout = cache_timeout): """ """ data = {'article':text_inp} content = read_url(base_url+req_type[0],urlencode(data),headers,timeout) return content def get_lymbix_flag_response(text_inp,timeout = cache_timeout): """ """ data = {'article':text_inp} content = read_url(base_url+req_type[0],urlencode(data),headers,timeout) return content def main(): set_initial_stuff() return get_lymbix_tonalize(sys.argv[1]) if __name__ == '__main__': print main()