I have created a python script which extracts some links from a website using beautiful soup. Now this python script writes an HTML code and saves it to an HTML file, say test.html. Whenever the user clicks refresh button on his Android app (created using jQuery Mobile), I want to display test.html in the app. How can I so this?
-
Where does test.html live? On a website? When the user clicks the refresh button do you want test.html to be generated, or is the python script already running on a cron job? – dstudeba Jun 26 '15 at 21:47
-
When the user clicks refresh, I want test.html to be generated. That means everytime the user clicks refresh, I want the python script to be executed. Currently everything is on my local machine. – Utkarsh Chauhan Jun 26 '15 at 21:56
1 Answers
Instead of writing out the test.html file you should return it as the output of the python script. So your python script will sit on your webserver as an API. Your Android app will call the python script asynchronously and when the python script finishes it will return the test.html contents as a string to your app to display. If the python script takes a long time you may want to run it continuously on your server and then serve the results from a file.
Edited to add: Here is a post to send you down the road of setting up your python script to be accessible with an HTTP request. How to run python script in webpage
Edited again to add: Here is a post on asynchronous in Android : http://www.justinmccandless.com/blog/Now+in+Android%3A+Asynchronous+Web+API+Calls
Also documentation on HTTP calls: http://developer.android.com/reference/java/net/HttpURLConnection.html
-
Thanks for the help. One more thing. How can I make the python script sit in a webserver as an API? And how to call the python script asynchronously from the app? – Utkarsh Chauhan Jun 26 '15 at 22:19
-
Try the three links I added to the answer, hopefully those will help! – dstudeba Jun 26 '15 at 22:34