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
-
Sorry in advance for this stupid question. But is it possible to have bottle running in Pythonista and have another script run that is using requests? I am guessing not, but maybe there is a trick to do this.
I know I can use safari to see results etc, but it's painful process. -
You might be able to run one in Editorial and the other in Pythonista. How would that be for crazy?!?
-
@ccc, really?? It was that easy 🆒
A good reason for every one to have editorial also 😁
But again, thank you. This is great. I just got it running in Editorial and the url just returns a dict. In Pythonista, just ran
import requests msg_url = 'http://localhost:8080/hello' def msg_get(url): x= requests.request('GET', url) print x.json() if __name__ == '__main__': msg_get(msg_url)
And got my dict back. Super cool. Editorial timed out running the script, but I haven't tried for it not to time out yet. I am sure I will find it. Now 1:47am here, I have been here since 1pm. Time to have a sleep 😃
But I am really excited about this... I have yacc or yaci (yet another cool idea )
-
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.