|
1 | | -import pytesseract |
2 | | -from pdf2image import convert_from_path |
3 | | -import PyPDF2 |
4 | 1 | import json |
| 2 | +import PyPDF2 |
5 | 3 | import tempfile |
| 4 | +import requests |
| 5 | +import pytesseract |
| 6 | +from pdf2image import convert_from_path |
6 | 7 |
|
7 | 8 | from walkoff_app_sdk.app_base import AppBase |
8 | 9 |
|
@@ -59,10 +60,6 @@ def generate_report(self, apikey, input_data, report_title, report_name="generat |
59 | 60 | report_name = report_name + ".html" |
60 | 61 |
|
61 | 62 | report_name = report_name.replace(" ", "_", -1) |
62 | | - |
63 | | - if not formatting: |
64 | | - formatting = "auto" |
65 | | - |
66 | 63 | output_formatting= "Format the following text into an HTML report with relevant graphs and tables. Title of the report should be {report_title}." |
67 | 64 | ret = requests.post( |
68 | 65 | "https://shuffler.io/api/v1/conversation", |
@@ -217,5 +214,79 @@ def gpt(self, input_text): |
217 | 214 | "reason": "Not implemented yet" |
218 | 215 | } |
219 | 216 |
|
| 217 | + def run_schemaless(self, category, action, app_name="", fields=""): |
| 218 | + """ |
| 219 | + action := shuffle.CategoryAction{ |
| 220 | + Label: step.Name, |
| 221 | + Category: step.Category, |
| 222 | + AppName: step.AppName, |
| 223 | + Fields: step.Fields, |
| 224 | +
|
| 225 | + Environment: step.Environment, |
| 226 | +
|
| 227 | + SkipWorkflow: true, |
| 228 | + } |
| 229 | + """ |
| 230 | + |
| 231 | + data = { |
| 232 | + "label": action, |
| 233 | + "category": category, |
| 234 | + |
| 235 | + "app_name": "", |
| 236 | + "fields": [], |
| 237 | + |
| 238 | + "skip_workflow": True, |
| 239 | + } |
| 240 | + |
| 241 | + if app_name: |
| 242 | + data["app_name"] = app_name |
| 243 | + |
| 244 | + if fields: |
| 245 | + if isinstance(fields, list): |
| 246 | + data["fields"] = fields |
| 247 | + |
| 248 | + elif isinstance(fields, dict): |
| 249 | + for key, value in fields.items(): |
| 250 | + data["fields"].append({ |
| 251 | + "key": key, |
| 252 | + "value": str(value), |
| 253 | + }) |
| 254 | + |
| 255 | + else: |
| 256 | + try: |
| 257 | + loadedfields = json.loads(fields) |
| 258 | + for key, value in loadedfields.items(): |
| 259 | + data["fields"].append({ |
| 260 | + "key": key, |
| 261 | + "value": value, |
| 262 | + }) |
| 263 | + |
| 264 | + except Exception as e: |
| 265 | + print("[ERROR] Failed to load fields as JSON: %s" % e) |
| 266 | + return json.dumps({ |
| 267 | + "success": False, |
| 268 | + "reason": "Ensure Fields are valid JSON", |
| 269 | + "type": type(fields), |
| 270 | + "details": "%s" % e, |
| 271 | + }) |
| 272 | + |
| 273 | + |
| 274 | + baseurl = "%s/api/v1/apps/categories/run" % self.base_url |
| 275 | + baseurl += "?execution_id=%s&authorization=%s" % (self.current_execution_id, self.authorization) |
| 276 | + |
| 277 | + print("[DEBUG] Running schemaless action with URL '%s', category %s and action label %s" % (baseurl, category, action)) |
| 278 | + |
| 279 | + headers = {} |
| 280 | + request = requests.post( |
| 281 | + baseurl, |
| 282 | + json=data, |
| 283 | + headers=headers, |
| 284 | + ) |
| 285 | + |
| 286 | + try: |
| 287 | + return request.json() |
| 288 | + except: |
| 289 | + return request.text |
| 290 | + |
220 | 291 | if __name__ == "__main__": |
221 | 292 | Tools.run() |
0 commit comments