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.
Sharing Code on GitHub
-
One of the easiest ways to share code that you've written in Pythonista is to create a Gist on GitHub. You can do this directly from the built-in "Export..." menu and you don't even need a GitHub account if you select the "Anonymous" option.
After you've created the Gist, its URL will be in the clipboard.
So far, so good. But what if you want to try out a Gist that someone else has posted? Sure, you could copy its text from Safari and paste it into a new script, but there has to be a better way, right? Luckily, Pythonista's actions menu is extensible with your own scripts – so here is a script that lets you import a Gist from a URL in the clipboard:
https://gist.github.com/b0644f5ed1d94bd32805
Just copy it into a new script, rename it to something like "New from Gist" and add it to the editor menu in the settings. Voilà: now you can import a Gist from someone else with just two taps – no need to copy and paste or even open Safari. Enjoy!
-
Awesome, very useful. I tweaked the script to support multiple files - at https://gist.github.com/4036200 - it appears to work, but caveat emptor. Hope it's useful to someone anyway.
-
Is this the good way?
https://gist.github.com/4039885
my version 0.7 of 'mydirectory.py'???stuk!! please give me an example how to adjust the script b0644f5ed1d94bd32805
-
Interesting idea! Not sure if the scene module is really a good place to start something like that though. Perhaps it would be easier to make something text-based first... You could use raw_input for a simple text command-based "interface" and just print everything at first. I guess that would be easier to debug and you wouldn't have to worry about implementing all that scrolling logic etc.
-
I have just updated the multifile gist example with my own:
https://gist.github.com/5f3f2035d8aa46de42ad
Save that as "gist" and add the following bookmarklet called "Get Gist" to safari:
javascript:(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href='pythonista://gist?action=run&argv='+document.location.href;%7D)();
Now, whenever you are looking at a gist script that you want to try in Pythonista, just click the bookmarklet and it will instantly download and display the code for you. Enjoy!
-
I wanted to be able to write repeatedly to the same gist, so I wrote a little script that lets you write to and pull from a gist.
https://gist.github.com/4043334
If you just run the script, it will write three additional small scripts into your library. These additional scripts provide editor actions to set the gist associated with a file, commit to a gist, and pull from a gist. I haven't added support for creating gists yet...
Anyway if you have an exiting gist with a file that you want to pull, you can create a blank file in the library with the same file name, run the gistcheck_set action to set the associated gist for the file (the value you enter should just be the gist id, that is 4043334 in the link above), then run the gistcheck_pull action. You'll end up with a copy of the file from the gist. Edit it as you desire. Then you can publish the changed version back using the gistcheck_commit action.
Don't know if anyone else will find this useful, but I hope it helps someone.
-
Thanks, didn't notice that. Here's a quick workaround that strips non-ASCII characters from the downloaded gist:
https://gist.github.com/4076735
I plan to improve theeditor
module's unicode support in a future update.Those Hue light bulbs look awesome!
-
Finally understood the gist(pull) script, works , happy Peter
-
I combined meu's script for pulling from/committing to gists with C0deH4cker's version of the gist downloading script, so that newly downloaded gists automatically have their IDs set, for future pulling/committing.
It's posted at:
https://gist.github.com/4145515Details on using it are largely the same as it was for the two scripts it's based on, however some filenames are changed to make it look nicer. See the comment at the top of the source file for more details. (To use this script's version of Download Gist.py, you should delete any existing file with that exact name before running my script, which will then set up the replacement.)
-
so how do you get any of these scripts initially pasted into pythonista in the first place? When I view them in safari from the iPhone, I'm not seeing any way to copy the contents to the clipboard. The "copy" command just copies the URL to the page.
-
please disregard the above - figured it out :) I needed to tap and HOLD longer to get into the select mode. duh!
-
Starting with Westacular's Gist, I did a rework of gistcheck.
https://gist.github.com/4702275
Changes:
- General code refactor including switching to requests and shelve module to make handling of the api and gist_id database easier.
- Renamed action scripts to start with "Gist" for easier grouping.
- New ability to create Gist. Calling "Gist Commit" on a file with no Gist ID set will create a new Gist and set the gist_id on the file correctly.
- Added some URL patterns to allow more forms of URLs to be passed in for stripping the Gist ID.
Thanks for all of the previous work, I've been using gistcheck to keep my iphone and ipad pythonista installs synced up. I'm considering adding a script to Sync particular gists to make keeping multiple files update date easier.
-
Hi,
I'm havign a problem getting this to work. I've grabbed spencerogden's gist and run it as described. This gives me the four scripts.
I then tried to create a new file and commit it (as a new gist). When I try to do so it fails at the authorisation phase with the error:
"An error occurred while running the action 'Gist Commit': KeyError:'token'"
When I look at the return from the call to auth() I see:
{u'message': u'Not Found'}
which explains why I get the key error, but doesn't explain why I would get that return.
I have tried random credentials and this gives a different error (sensibly related to bad credentials)
I noticed one possible issue in the auth() function, I think there may be a problem with the call to api_url.replace
It replaces 'gist' with 'authorizations' which, given the original url will make the end of the subsequent url:
/authorizationss/
with an extra 's'
However, correcting this makes no difference.
What am I missing?
Thanks
Dave
-
Dave, that script uses an outdated authentification method. Use Westacular's script instead (worked for me).
-
Thanks,
I grabbed spencerogden's because I wanted the ability to create a new gist. I've therefore done a simple hack and used Westacular's auth() function in spencerogdon's version. I haven't done extensive testing, but it seems to work fine.
It's available here:
https://gist.github.com/5212628
Cheers
Dave
-
@davenicholls: thanks to you and all the previous authors of this script. I've started using your version and it is very useful. I have one comment and one question:
Comment: I think the script must be named as "gistcheck" or the edit menu actions won't work - they give an error message that module gistcheck can't be found. This might be self-evident to an experienced Pythonista user but caused me some head-scratching. Perhaps you could add a sentence to the script to instruct users?
Question: I've noticed that all the scripts referenced in this thread are public and anonymous, so the URL does not include the userid, and the gist id is a five-digit number. Private gist ids seem to be much longer alphanumeric strings. For personal programming projects, is it better to use the public option to keep the readable ids?
-
@johnbenallan
You're right, the four scripts all reference the original one so it must be called gistcheck.py. I picked this up from an earlier comment, but I have now added it as a comment to my fork of the original.
I followed the convention of this thread and posted the shorter, anonymous, gist link although it does end up being redirected to my account so it doesn't remain anonymous.
On my iPad I use a slightly modified version of the script, the lines:
if message is not None: payload['description'] = message for f, c in files.items(): payload['files'][os.path.basename(f)] = {"content":c}
are replaced by
if message is not None: payload['description'] = message payload['public'] = False for f, c in files.items(): payload['files'][os.path.basename(f)] = {"content":c}'
Which creates a private gist.
Dave
-
@wbwelcomeback It's a known bug, sorry about that. You can work around it for now by putting an additional script in the menu that comes before it (they're sorted alphabetically, and the first one currently doesn't work on the iPhone).
-
And btw, it's not possible to include these features as part of the app, it wouldn't pass Apple's review (downloading code in any way is a no-no).
-
I have the same problem of LOT17111, " The Gist could not be downloaded..."