Skip to content

Instantly share code, notes, and snippets.

@rohithBirdeye
Created March 26, 2019 07:14
Show Gist options
  • Save rohithBirdeye/bfd4c0486b84df711773692d0951e14e to your computer and use it in GitHub Desktop.
Save rohithBirdeye/bfd4c0486b84df711773692d0951e14e to your computer and use it in GitHub Desktop.
@ResponseBody
@GetMapping(value = "/test/python", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> testPython() throws Exception{
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("interp.py").getFile());
File leadModel = new File(classLoader.getResource("leadmodel.model").getFile());
String[] command = { "/usr/local/bin/python3", file.getAbsolutePath(),"score",leadModel.getAbsolutePath() ,
"{\"Lead ID\": \"00Q3600000WVCNL\", \"Company / Account\": \"Parham Law Firm LLC\", "
+ " \"Industry1\": \"Legal\", \"Marketing Channel\": \"Product emails\", \"Lead Campaign\": "
+ "\"product_email\", \"Lead Sub Campaign\": \"follow_up_v2\", "
+ " \"Lead Campaign KW\": \"%2Bgoogles%20%2Breviews\", "
+ " \"Lead Intent\": 1, \"Lead Life Cycle\": \"Downgrade - Bad Data/Test\", "
+ " \"Country\": \"United States\", \"City\": \"Atlanta\", \"State/Province\": \"Georgia\", "
+ " \"Zip/Postal Code\": 30339, \"Business Locations\": 1, \"Business Phone\": \"(678) 439-1482\", "
+ " \"Website\": \"www.parhamlaw.net\" }" };
//Process p = Runtime.getRuntime().exec(new String[] {"/usr/local/bin/python3", "/interp.py", "score" , "/leadmodel" ,"{\"Lead ID\": \"00Q3600000WVCNL\", \"Company / Account\": \"Parham Law Firm LLC\", \"Industry1\": \"Legal\", \"Marketing Channel\": \"Product emails\", \"Lead Campaign\": \"product_email\", \"Lead Sub Campaign\": \"follow_up_v2\", \"Lead Campaign KW\": \"%2Bgoogles%20%2Breviews\", \"Lead Intent\": 1, \"Lead Life Cycle\": \"Downgrade - Bad Data/Test\", \"Country\": \"United States\", \"City\": \"Atlanta\", \"State/Province\": \"Georgia\", \"Zip/Postal Code\": 30339, \"Business Locations\": 1, \"Business Phone\": \"(678) 439-1482\", \"Website\": \"www.parhamlaw.net\" }" });
Process p = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line + "\n");
}
String ret = in.readLine();
System.out.println("value is : "+ret);
return new ResponseEntity<>(ret, HttpStatus.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment