-
SpotlightKid
Thanks for the heads up!
There was an error in the regex to parse the bottle version. Should be fixed now. Your approach unfortunately wouldn't work with version strings like '0.13-dev'. Anyway, I think on Python 2 the version of bottle included with Pythonista should be fine, so I adapted the code to reflect this too.
-
SpotlightKid
Hi all,
I needed a way to make my iPad display images scaled to fullscreen without taking my hands off the keyboard/mouse of my main computer. Thus ImageFrame.py was born:
http://tinyurl.com/iosimageframe
Just run this script in Pythonista and it will start up with a fullscreen display of the 'test:Lenna' image included in Pythonista. Then use the provided script send-image.py on your main computer to upload an image and have it displayed instead (requires the requests library). The image is added to the Photo Library on your iOS device in an album called "Image Frame" (which will be created if it does not exist yet). I add this script as a handler for images to the right-click context menu of my file browser. You can also point your browser to http://<ip of your ios device>:8080/ and upload an image via an HTML form. Use a 2-finger wipe down to end the script.
I use this for displaying reference images while drawing or cheat sheets for keyboard shortcuts or programming languages while coding. But it also makes it possible to use your iPad as an over-priced digital image frame ;)
Bugs / Areas for possible future improvements:
- Runs on Pythonista 2 or 3, although on Pythonista 3 there are some problems with uploading images through the browser. The send-image.py script simply sends the image via HTTP PUT and this works without problems on both Pythonista 2 and 3.
- No authentication whatsoever
- You need to pass the IP address of your iOS device to the upload script or edit it to set the default.
- The network status, clock and battery status are always displayed at the top of the screen.
- Some sort of automatic slideshow display would be nice.
Share & Enjoy, Chris
-
SpotlightKid
That's what I would think too. Apparently Apple doesn't. If you can't live with this, don't use Apple products. Life's a bitch.
-
SpotlightKid
The easiest way for me is usually the Dropbox File Picker.
Your need to do some initial setup as explained in the comments at the start of the file, but then it's easy and convenient.
-
SpotlightKid
How about putting the month in the filename:
filename = "data-%s-%02i.csv" % (stock.replace('^', ''), startdate.month)
-
SpotlightKid
Small suggestion:
from datetime import datetime, date [...] month = int(datetime.strftime(date.today(), "%m")) - 1 year = int(datetime.strftime(date.today(), "%Y"))
This can be just written as:
from datetime import date month = date.today().month - 1 year = date.today().year
No need to format the month/year number into a string and then into an integer again.
-
SpotlightKid
BTW, if you want to play with the URL parameters (params a-f can be used to set a date range), you can construct the URL params from a dictionary like so (note that the month number has to be minus one):
STOCK_URL = 'http://ichart.finance.yahoo.com/table.csv' PARAMS = { 'a': 9, 'b': 1, 'c': 2014, 'd': 9, 'e': 31, 'f': 2014, 'g': 'd', 'ignore': '.csv' } def pulldata(stock, filename): params = PARAMS.copy() params['s'] = stock url = "%s?%s" % (STOCK_URL, urllib.urlencode(params)) return urllib.urlretrieve(url, filename)
Here's the documentation of the API:
https://code.google.com/p/yahoo-finance-managed/wiki/csvHistQuotesDownload
-
SpotlightKid
The File2Txt.py file could be written much shorter using
shutil.copy()
andos.path.splitext()
.In Python is pays to know your standard library well.
-
SpotlightKid
RUT doesn't seem to be a valid stock identifier. Try '^GDAXI' for the German DAX.
-
SpotlightKid
Just pass the path of the output file as a second argument to
urlretrieve()
. The filename is also the first item of the tuple returned by this function.import urllib STOCK_URL = 'http://ichart.finance.yahoo.com/table.csv?s=%s&a=07&b=25&c=2014&d=07&e=29&f=2014&g=d&ignore=.csv' def pulldata(stock, filename): return urllib.urlretrieve(STOCK_URL % urllib.quote(stock), filename) filename, headers = pulldata("RUT", "RUT-data.csv")
If you want to save the file in your documents folder, build the filename like this (there are several ways to do this, but this one will work on desktop Python as well):
import os from os.path import exists, dirname, join # create output directory if it doesn't exist yet documents = join(os.getenv('HOME'), 'Documents') if not exists(documents): os.mkdir(documents) filename = join(documents, 'RUT-data.csv')
-
-
SpotlightKid
If you have a user account on the Linux server and it is running a SSH service (which it probably is), SFTP ist the protocol you're looking for. Pythonista comes with the paramiko module, which has support for SFTP.
The paramiko repository has an example script for uploading files via SFTP:
https://github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
-
SpotlightKid
The Python code editors I use on the desktop insert a set amount of spaces (4) when I press tab or remove them, when I use backspace at the beginning of the line.
My strong opinion on tabs is: they have no place in Python code.
-
SpotlightKid
I always wondered why many coders here do not follow PEP-8. Apart from the tab/spaces thing, variable naming comes to mind. IMHO mixedCase for function, method, and variable names isn't really well-liked in the Python world. Also, I see many whitespace-related style errors in code posted here.
-
-
SpotlightKid
I'm not really (atm) interested in sound generation on the iDevice but actually in MIDI in itself to control external devices or to act as a MIDI filter or processor.
-
-
SpotlightKid
I'm currently reading this on my iPad:
Which is about data structures, models and simulations and for people who already know Python.
The same author has an introductory Python book:
Think Python - How to Think Like a Computer Scientist
You can buy the books or download free PDFs of earlier versions or read the HTML version online.
-
SpotlightKid
If you install the script via the
gitrepo.uipack.py
download, the unpackedgitrepo.py
will have a syntax error on line 21:parselink = re.compile("<[\S]*?page=(\d+)>; rel="last"").search
i.e. the escaping of the double quotes is lost.
I suggest just using this syntax instead:
parselink = re.compile(r'<[\S]*?page=(\d+)>; rel="last"').search
Please note that I also made the string literal a raw string by prefixing it with
r
. This is generally a good practice for regular expression strings, since the backslash in combination with certain characters will be interpreted as an escape sequence otherwise and the regex may not work as intended. -