| 35 | |
| 36 | # algo run <algo> <args..> run the the specified algo |
| 37 | def runalgo(self, options, client): |
| 38 | algo_input = None |
| 39 | |
| 40 | algo = client.algo(options.algo) |
| 41 | url = client.apiAddress + algo.url |
| 42 | result = None |
| 43 | content = None |
| 44 | |
| 45 | algo.set_options(timeout=options.timeout, stdout=options.debug) |
| 46 | |
| 47 | # handle input type flags |
| 48 | if (options.data != None): |
| 49 | # data |
| 50 | algo_input = options.data |
| 51 | |
| 52 | result = algo.pipe(algo_input) |
| 53 | |
| 54 | elif (options.text != None): |
| 55 | # text |
| 56 | algo_input = options.text |
| 57 | key = self.getAPIkey(options.profile) |
| 58 | content = 'text/plain' |
| 59 | algo_input = algo_input.encode('utf-8') |
| 60 | |
| 61 | elif (options.json != None): |
| 62 | # json |
| 63 | algo_input = options.json |
| 64 | key = self.getAPIkey(options.profile) |
| 65 | content = 'application/json' |
| 66 | |
| 67 | elif (options.binary != None): |
| 68 | # binary |
| 69 | algo_input = bytes(options.binary) |
| 70 | |
| 71 | key = self.getAPIkey(options.profile) |
| 72 | content = 'application/octet-stream' |
| 73 | |
| 74 | elif (options.data_file != None): |
| 75 | # data file |
| 76 | algo_input = open(options.data_file, "r").read() |
| 77 | result = algo.pipe(algo_input) |
| 78 | |
| 79 | elif (options.text_file != None): |
| 80 | # text file |
| 81 | algo_input = open(options.text_file, "r").read() |
| 82 | key = self.getAPIkey(options.profile) |
| 83 | content = 'text/plain' |
| 84 | algo_input = algo_input.encode('utf-8') |
| 85 | |
| 86 | elif (options.json_file != None): |
| 87 | # json file |
| 88 | # read json file and run algo with that input bypassing the auto detection of input type in pipe |
| 89 | with open(options.json_file, "r") as f: |
| 90 | algo_input = f.read() |
| 91 | key = self.getAPIkey(options.profile) |
| 92 | content = 'application/json' |
| 93 | algo_input = json.dumps(algo_input).encode('utf-8') |
| 94 | |