I would like to set up a webpage that takes a number of Facebook status updates via the Javascript API and sorts them into an array. Then I'd like to send this array to a Python script, which can specifically do language analysis with NLTK. After I get a suitable result in Python, I'd like to return the result from that script to Javascript for displaying to the user, etc. Does this sound possible?
-
2Why don't you just use json?Matti John– Matti John2013-04-25 14:56:11 +00:00Commented Apr 25, 2013 at 14:56
-
Use json for what? With NLTK? Does that work?jumbopap– jumbopap2013-04-25 14:58:35 +00:00Commented Apr 25, 2013 at 14:58
-
Use json for communicating between Python and JavaScript.kindall– kindall2013-04-25 15:02:38 +00:00Commented Apr 25, 2013 at 15:02
-
I meant you can simply parse the Javascript API result using the json module in the standard library, which will return a python object which you can then presumably use in NLTKMatti John– Matti John2013-04-25 15:02:55 +00:00Commented Apr 25, 2013 at 15:02
-
Any resources showing how to do that with an array would be helpful.jumbopap– jumbopap2013-04-25 15:13:48 +00:00Commented Apr 25, 2013 at 15:13
2 Answers
Yes, totally. Check out Google App Engine to build this sort of functionality. In particular check out these links:
NLTK on App Engine: Using the Python NLTK (2.0b5) on the Google App Engine and http://code.google.com/p/nltk-gae/
Facebook API on App Engine: https://developers.google.com/appengine/articles/shelftalkers
I assume that you want to make it interactive because you mentioned the word "user".
2 Comments
Calling a service from Javascript is a very common problem. One way of solving it is to write a specific type of website known as a Webservice which would make the process flow something like...
- Javascript uses Ajax (Asynchronous Javascript and XML) to send an HTTP Request to your Webservice containing the information you want to process.
- The Webservice receives the request and performs the requested processing (eg by invoking the NLTK)
- The resulting data is sent back over the same Http connection
- A javascript function is called and passed the results of the data
The easiest way to send a request is using jQuery. The easiest way to format the data to be passed back and forth is JSON (JavaScript Object Notation).
An example call would look something like this...
$.json({
url: "/url/of/Webservice",
data: {
"SomeKey": "SomeValue",
"SomeList": ["Item1", "Item2", "Item3"]
/*... etc */
}
}).done(function(response) {
//Assuming a response that looks like this: {"Result": "Some Result"}
alert("The Webservice said: " + response.Result);
});
It's up to you how you'd implement the Webservice. If you want to use Python, Django is one of many good frameworks to get you started