A Simple HTTP Server
If you want to download files in Pythonista to your Mac or PC or are maybe just interested in learning a little more about Python's networking modules, you might find this little script useful:
(use the <a href="http://omz-software.com/pythonista/forums/discussion/5/sharing-code-on-github#Item_1">New from Gist</a> script to import it easily)
It shows how to create a basic HTTP server that runs on your iPad/iPhone and allows you to download/upload files from/to Pythonista, using a regular web browser on a different machine.
This should work for printing the IP address:
import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('184.108.40.206',80)) print s.getsockname() s.close()
(From this answer on StackOverflow)
Now it works.
iOS automatically stops background app about 10 minutes.
Is there any way to run pythonista server script "forever" (over 24 hours) in background?
Thanks for asking that question @duffy . It's what ultimately inhibited my using a Pythonista HTTP Server to provide a web page in slide over that acts as a toolbar.
It seems that @ccc has a good solution:
I haven't tried that myself so I'm not sure it will work in that particular case, but give it a shot!
I tried it. But this have effect only in the foreground.
You could try no_doze.py but it is not pretty.
I tried no_doze.py in iOS9. but it did not relaunch self. I think iOS changed behavior.
reincarnate(argv) # Silent notification can relaunch self
You can try this
@brumm That got removed from the released version in app review.
If you want your app to live, it needs to be in the foreground.
I believe we can use
from the main app to run code when we area about to be killed. Also, app.backgroundTimeRemaining does give remaining time, though not sure if this is a guaranteed kill when the timer reaches 0
@JonB It's redundant to call
beginBackgroundTaskWithExpirationHandleryourself; Pythonista already does that when you run a script (otherwise, the app would be suspended immediately when in the background), and you don't get more background time by starting multiple background tasks.
I don't have a way of trying this (no Mac), but is it possible by packaging a script with the Xcode template, applying the right settings in the p.list and then loading the app manually on your phone?
I wonder if anyone has tried that...
The script would also need to do something that iOS allows in the background. (Example: Playing a silent MP3 on infinite loop).
@cook it should be.