Hi,
I want to create a page in AEM that uses yowsup. Yowsup is an api written in python for messaging to whatsapp.
I would like to write an application extension of the Yosup in Python, then call that in API.
Am I even trying something reasonable.
Regards
Clive Stewart
Solved! Go to Solution.
Views
Replies
Total Likes
As fa as I know about Yowsup, Yowsup is a python library that enables you build application which use WhatsApp service.
yowsup-cli is a command line interface to Yowsup library.
We need to use yowsup-cli for sending or reciveing messages.
So you can create a OSGI Sling service from which you can call Python scripts.
Option 1:-
//Link:- http://blog.xebia.in/2013/11/25/yowsup-the-whatsapp-api/
To embed it in Java, all you have to do is call this command from Java's process builder framework. For this, first create a shell script to send message. Name it `sendMessage.sh` which looks like:
#!/bin/bash
python yowsup-cli -c config.example -s $1 "$2"
String message = "The message goes here";
String[] sendCommand = { "/bin/bash", “path/to/sendMessage.sh”, "<to number including cc>", message };
ProcessBuilder processBuilder = new ProcessBuilder();processBuilder.directory(new File(<YOWSUP_HOME>));
processBuilder.environment().put("PYTHONPATH", <YOWSUP_HOME>);
processBuilder.command(sendCommand);
System.out.println(processBuilder.environment());
Process process = processBuilder.start();
process.waitFor();
8. Run the above program and your message will be sent to the intended receiver.
9. You can read the ` process.getInputStream()` to get the output of the script you executed. For ex-
InputStream stream = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String str = null;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
Option 2:-
//Link:- http://stackoverflow.com/questions/16447410/how-to-execute-python-script-from-java
Execute Python script from Java?
Put your command to a shell script and execute that shell script with .exec() or
You can do something similar to the following
String[] cmd = {
"/bin/bash",
"-c",
"echo password | python script.py '" + packet.toString() + "'"
};
Runtime.getRuntime().exec(cmd);
I am not sure about if we can do something with REST APIs, if we have rest framework for Yowsup, then we can call the APIs from OSGI Sling Service.
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Clive,
"I want to create a page in AEM that uses
---Jitendra
Clive Stewart wrote...
Hi,
I want to create a page in AEM that uses
yowsup .Yowsup is anapi written in python for messaging to
I would like to write an application extension of the Yosup in Python, then call that in
API .
Am I even trying something reasonable.
Regards
Clive Stewart
Views
Replies
Total Likes
This seems a classic java python integration use case. I hope following would be helpful-
http://stackoverflow.com/questions/1119696/java-python-integration
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
Views
Replies
Total Likes
As fa as I know about Yowsup, Yowsup is a python library that enables you build application which use WhatsApp service.
yowsup-cli is a command line interface to Yowsup library.
We need to use yowsup-cli for sending or reciveing messages.
So you can create a OSGI Sling service from which you can call Python scripts.
Option 1:-
//Link:- http://blog.xebia.in/2013/11/25/yowsup-the-whatsapp-api/
To embed it in Java, all you have to do is call this command from Java's process builder framework. For this, first create a shell script to send message. Name it `sendMessage.sh` which looks like:
#!/bin/bash
python yowsup-cli -c config.example -s $1 "$2"
String message = "The message goes here";
String[] sendCommand = { "/bin/bash", “path/to/sendMessage.sh”, "<to number including cc>", message };
ProcessBuilder processBuilder = new ProcessBuilder();processBuilder.directory(new File(<YOWSUP_HOME>));
processBuilder.environment().put("PYTHONPATH", <YOWSUP_HOME>);
processBuilder.command(sendCommand);
System.out.println(processBuilder.environment());
Process process = processBuilder.start();
process.waitFor();
8. Run the above program and your message will be sent to the intended receiver.
9. You can read the ` process.getInputStream()` to get the output of the script you executed. For ex-
InputStream stream = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String str = null;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
Option 2:-
//Link:- http://stackoverflow.com/questions/16447410/how-to-execute-python-script-from-java
Execute Python script from Java?
Put your command to a shell script and execute that shell script with .exec() or
You can do something similar to the following
String[] cmd = {
"/bin/bash",
"-c",
"echo password | python script.py '" + packet.toString() + "'"
};
Runtime.getRuntime().exec(cmd);
I am not sure about if we can do something with REST APIs, if we have rest framework for Yowsup, then we can call the APIs from OSGI Sling Service.
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Apologies, my question was not well formed. I am basically looking to call a python application from within Java
Views
Replies
Total Likes
Thank you,
This is exactly what I was looking for.
Views
Replies
Total Likes
Thank you for the links, you are correct, it is a basic Python - Java integration issue
Views
Replies
Total Likes
Views
Likes
Replies