Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Running Bottle in Pythonista and another script also
-
Requests is such a great API because it does wonderful complexity hiding and at the same time allows you to pack so many transforms into a single, short call. You could also write:
import pprint, requests url = 'http://localhost:8080/hello' if __name__ == '__main__': pprint.pprint(requests.get(url).json())
-
Untested, but it seems to me if you present a ui, with a button action that runs your
requests
app, then start the server, you can run one inside the same app. I believe Cethric has an HTML testing app that does this. -
i did test this for launching the bottle script. instead of just run(host=....), use a threading.Thread
# coding: utf-8 from bottle import route, run from threading import Thread import requests @route('/hello') def hello(): return "Hello World!" #run t=Thread(target=run,kwargs={'host':'localhost', 'port':8080, 'debug':True}) t.start() print requests.get('http://localhost:8080/hello').content
-
@JonB , with your Thread test, did it work? I got at 61 error connection refused. I closed all my browser safari Windows, I terminated editorial and re started Pythonista, just to be sure I didn't have something open all ready.
I tried it both in Pythonista and editorial, got the same error. Any ideas?But if I get past this point, I will try running in a panel in Pythonista
-
This is a timing thing... If you insert a time.sleep(1) then you will get a connection. Flask lets you run(threading=True) but I do not see that same capability in Bottle.
-
@ccc , yes requests looks great. Hopefully it's as simple to use at it appears. I have done no web programming. But I would like to create a very simple form app. Just want to do this via simple messaging with dicts. On the backend use SQLite. But I really want to keep it simple (KISS) because that's all I am capable of at the moment. I wrote a simple messaging protocol many years ago to talk with mainframes and mini's. It was text based and very simple. But still easy to extend and implement. We didn't get grief from the backend programmers. But because of knowledge of apple events at that time, it gave me the idea how to be extensible.
But anyway, to begin with, using the dialogs module, I want to be able to easily create a form and post it to the backend which will write it to a SQLite db. Of course then to be able to retrieve info. But again, I need to keep it so simple. Otherwise I will be off learning all sorts of new stuff again. I think it should be possible. I also have a PythonAnywhere account, which includes bottle. So I have a place to host.
Anyway, I will try 😇😭😀👍 -
@omz Are you deprecating the support for Flask in Pythonista v2.0 or will both Bottle and Flask be supported? I noticed that code completion for Falsk is not working in the latest beta.
-
@ccc No, Flask support is not deprecated at all. I've actually added it in 2.0, it's just that the documentation is missing for now. Code completion should still work via Jedi, it's just a bit slower than it would be if it could use the documentation index.
-
@ccc , given the simple job I am trying to do, do you think bottle is the best for the job. From what I read about mini or micro web frame works, bottle seems to be the simplest
-
I updated with the missing line (t.start()), and this did work as written (sorry, this post didnt get posted)
I am not exactly clear how to kill the server though-it survives global clears. Putting a KeyboardException inside the hello() works, but you could also just reuse the app() and just update route, etc.
-
@JonB, thanks. It works like that in Pythonista. If I add some routes to the bottle backend, it does not work as expected. But if I run it again, it works. Some errors are generated, but the new routes are live. But of course it can be fine tuned. Getting late for me now. I will try running the script from the tools menu tomorrow. Also it does say hit control c to quit. I will try sending the ESC seq for control c tomorrow various ways. Maybe that's the answer
-
The issue is there is not a good way to send a KeyboardInterrupt to a Thread.
You might be able to use default_app() and just usebottle.app().routes=[]
to clear out the old routes
-
@JonB , ok I will take a look thanks. I was just thinking about the debugging environment for the control c, as it comes up in the console to stop the server type control c
-
http://flask.pocoo.org/snippets/67/ Works for flask but something similar might work for Bottle.
-
This seems to be a more bottle-y way. I have not tried this on pythonista
-
I have tried the ways you guys suggested. I couldn't get the server to stop. For testing its ok though. I will just move on. I will use the thread version in Pythonista unless I have problems with it. If I have problems or it's funky, will move it to Editorial. But for testing both options are better than my expectations
-
Lol, I still haven't got back to this yet. I jump down one rabbit hole to find myself recursively jumping down other rabbit holes 😱😭
But I just had a idea the other day. Just wanted to share it in case it's not that dumb or had another use than my idea usage. My idea was just passing files to Editorial via bottle. Since editorial can link/sync to Dropbox in app, could present some interesting sync possibilities. I know this can be done direct to Dropbox with with the API. There was just something appealing about this idea. Anyway, maybe be crap, just a thought.
-
My sense would be that the best approach would be to use the Dropbox API on Pythonista and the builtin Dropbox capabilities of Editorial but to focus your efforts on simplicity and ease of setup/use. Slick and simple will beat convoluted almost every time.
-
@ccc , agreed 😱
-
@Phuket2 said:
I have tried the ways you guys suggested. I couldn't get the server to stop. For testing its ok though. I will just move on. I will use the thread version in Pythonista unless I have problems with it. If I have problems or it's funky, will move it to Editorial. But for testing both options are better than my expectations
This is possible with the latest StaSh. You can fetch it by running
selfupdate -f dev
(please restart Pythonista afterwards).A simple demonstration is as follows:
- StaSh comes with a
httpserver
command. So from StaSh, type and runhttpserver
. This starts the server in a separate thread. - Switch to the Pythonista's builtin console and use
requests
module to talk to the server, e.g.import requests; requests.get('http://localhost:8000').text
- Once you are done with the server, switch to StaSh and press the
CC
button (or Ctrl-C on external keyboard) to stop the server. The thread will be properly terminated with all of its resources (e.g. port number) released.
It is even possible to achieve above effects with just StaSh (i.e. don't need Pythonista console):
- Start the server by
httpserver &
(note the "&" character at the end) - Still inside StaSh, run
curl http://localhost:8000
- To stop the server, first run
jobs
to get the job ID of the running server. The output will be something like[4] Started httpserver.py &
. The number inside the square brackets is the job ID, i.e. 4 in this case. Now runkill 4
to terminate the server.
- StaSh comes with a