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.
Jono's Pythonista Scripts (Fast Image Sharing, Intuitive File Downloading and more)
-
Hey everyone, ever since I bought Pythonista I've been getting more and more into learning Python, generally by creating scripts to fix any little problems or inconveniences I come across in my day-to-day digital life. So far I've made scripts which enable pretty much one-tap image sharing across most messaging services on iOS, automatic file creation and downloading and conversion of any files to text which I find useful for reading files which Pythonista doesn't support opening, but which are readable in .txt format.
All of these can be found over at my GitHub repo here.
I would be very thankful for any constructive criticism as I'm basically using all this as a learning experience to better my programming skills. Thank you!
-
The script I find most useful is the Script downloader. I tried to port it for use in Editorial, but it says that url.read() attribute on line 82 isn't valid. I guess that function isn't in Editorial.
Edit:
It shows the same error in Pythonista. By the way, I am trying to get the .zip file from the link you posted. -
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.
-
@TutorialDoctor: Thanks for the bug report, I just uploaded the fix to both the uipack file and the normal .py, it was an error stemming from some experimentation I did with the ui.in_background() function that I forgot to remove before uploading. It's tested and working again, please let me know if you have any other issues with it :)
@SpotlightKid: I'll definitely look into those and attempt a re-write. Thank you for the advice!
-
Everything works in Pythonista now, and it appears to work in Editorial, but no I see no directory in Editorial.
Is the path the file is stored in relative to the location of the ScriptDownloader.py file? I wonder if you could make it to where a directory is created and the file is placed there, irrespective of the location of the python script.
Do you have Editorial? If so, I could send you a link to the workflow.
-
@TutorialDoctor: The path is indeed relative to the location of Script _ Downloader.py. I'm not sure how to ignore the working directory of the Downloader script as I'd have to know the root directory to do that but I've updated Script _ Downloader to now support paths. In the filename box, just add your path like so:
Master.zip in directory temp/zip-files would be "temp/zip-files/master.zip"
And the script will download the file to that directory. If the directory does not exist, it will make it and any parent directories as necessary. Again, this is probably going to be relative to the working directory of the script and I'm not too sure how to work around that. One hacky fix is to just have Script_Downloader in the root directory so it can work with any path but that's all I can really think of. I also made a few housekeeping changes to the code which are listed on GitHub but another main change is the inclusion of _ in the name instead of ' ' so it can be imported more easily in the console.Sadly I do not have Editorial so I can't test this stuff myself.
-
def parse_name(url): return url.rpartition('/')[2] or url def parse_extension(name): return os.path.splitext(name)[1].lstrip('.')
Also submitted as pull requests on your repo.
EDIT: fixed as recommended.
-
@ccc
Should the parameter under the parse_extension function be 'name'? I get an error that says the global 'url' is not defined.