-2

i am creating an android app which basically asks a user to enter a product name and then returns the best deals available for that particular product.I wrote a python script to scrape various ecommerce websites and return various deals available. What will be the best way to run this script with the product name from the app?

I am planning on creating a REST aPI and integrate that with my app but how do i run a python script through a RESTApi?

amora
  • 135
  • 2
  • 8

1 Answers1

3

Basically there is no easy way of implementin python in android. You will have to include a whole python. For developing android apps using python I would give Kivy a try.

You script seems to be using the internet. So why not hosting the Python Script online and fetching the data using json and parsing with java? This seemst to be the most simple solution. To start using python as a server you should take a look at Flask. It is very easy to understand. If you can't find a hoster for Flask there is PythonAnywhere and Heroku (for example)

fameman
  • 3,451
  • 1
  • 19
  • 31
  • After i host my python script online, how can i trigger its execution through my app? – amora Apr 09 '17 at 21:07
  • You just have to fetch the data from the server: Once you have set up your server script (lets say at `myserver.pythonanywhere.com/api` ) you could do something like this: http://stackoverflow.com/questions/14418021/get-text-from-web-page-to-string – fameman Apr 09 '17 at 21:11
  • Thank you so much. But how am i going to send the product name to that script? – amora Apr 09 '17 at 21:16
  • So you may have to send the username from the device using a POST request. That sounds more complicated than it is. In Flask you could then do: `@app.route("/api", methods=["GET", "POST"]) def api(): if request.method == "POST": username = request.form["username"] – fameman Apr 09 '17 at 21:19
  • Don't forget to import request from Flask: `from flask import request` – fameman Apr 09 '17 at 21:20
  • Since I am not a perfect java programmer, I unfortunately am not able to help more. I hope I could explain you a basic workaround for your problem ;-) – fameman Apr 09 '17 at 21:21
  • No problem. Welcome to StackOverflow :) – fameman Apr 09 '17 at 21:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/141307/discussion-between-amora-and-fameman). – amora Apr 09 '17 at 21:25