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.
Gist file retrieval
-
Using the Save to Gist is the easiest built in way to archive out your Pythonista files.
I am using it to save both my .py and .pyui files.
(Just select both and the hit the share sheet)Does anyone have a nice easy way to read a single Gist URL and save back all the associated files back into Pythonista?
(Ex Gist directory: https://gist.github.com/Mr-Coxall/4e21e9fe4ea65abcd9cd0d3ec094d0b7) -
gistcheck
https://gist.github.com/jsbain/1c95b3491d65d9e24456#
used to work, even for multi file gists, and allowed you to rev gists easily.. I don't think the bookmarklets work anymore in safari, or at least not ones that launch apps, and likely enough has changed in Pythonista3 that this won't work at all without some effort.
But this shows you how you could retrieve a gist using the gist api.
The way I tend to do this these days is with a simple App Extension (i.e from Safari share menu) script that download the current page into pythonista.
-
Do you have your script posted somewhere?
Be interested in seeing how it works.Thanks
-
i updated my savefile script to handle gists, including multi file gists.
Add to the appex shortcuts, then from safari simply Share-> Run Pythonista3 script->savedfile. For normal files, it will guess the name, and weite the file to your home folder. For gists it will create a gists/gis_id folder and download all files associated with the gist. -
-
Ok, that is totally awesome.
Works flawlessly and the .pyui file just opens up right into the GUI.One question.
I have both versions of Pythonista on my iPad.
The share sheet from Safari opens up Pythonista not Pythonista 3.
Any idea how to change That?Thanks again.
I am a much happier camper.
š -
-
Got the Pythonista 3 Sharesheet.
Thanks, i just thought it was a repeat. -
@JonB savefile is a great utility. There seems to be a bug and it gives error If the file contains unicode character. For example I am not able save this file.
https://gist.github.com/balachandrana/a0d9a42e1b66e054fe8b5e9a437c71b8I have modified your file as follows to make it work (convert the "content" to bytes). May be you can make appropriate changes.
console.hud_alert('writing '+filename) content=f['content'] with open(os.path.join(destpath,filename),'wb') as file: file.write(bytes(content, 'utf8')) else: console.hud_alert('could not download') else: destpath=urlfilename with open(destpath,'wb') as file: file.write(bytes(requests.get(url).content, 'utf8'))
-
-
Thanks for catching this -- I forgot that json was going to return a
str
..
I updated the gist. I actually opted for downloading the raw url, rather than using the content field -- in skimming the api, gists may sometimes be truncated, so redownloading the raw url takes care of both issues. (probably paranoid, but I am always wary of using json to capture truly binary data). Slightly wasteful, but gists are usually small enough. -
I have been trying different versions of Gist and Github downloaders and came up with the following solution after combining several together. It works with both Gists and Github repos. It does work with Unicode and it runs nicely from the sharesheet with some prompts to tell you what it is doing.
URL: https://gist.github.com/Mr-Coxall/7fbf6dc0ec3d83525f1944812ccce46f
# Created by: jsbain # Created on: Aug 2014 # URL : https://github.com/jsbain/GitHubGet/blob/master/GitHubGet.py # download an entire github repo. # either copy the url to clipboard, and run script, or run following bookmarklet. # will unzip to repo-branch (so be careful if downloading same branch name from multiple users) # ## javascript:(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href='pythonista://GitHubGet?action=run&argv='+document.location.href;%7D)(); # Altered by: Mr. Coxall # Altered on: Aug 2016 # Combined with other code, so that it will only work from sharesheet # and gives the user different and better feedback # Also places the files in Downloaded from Github directory # This works not only with Github repos but also Gists. import requests import appex, console, time, os import urllib, zipfile, sys, functools, re, os, tempfile #import urllib,zipfile,sys, clipboard, functools, re, os, tempfile def extract_git_id(git): #print git m = re.match((r'^http(s?)://([\w-]*\.)?github\.com/(?P<user>[\w-]+)/(?P<repo>[\w-]*)' '((/tree|/blob)/(?P<branch>[\w-]*))?'), git) # print m.groupdict() return m def git_download_from_args(args): if len(args) == 2: url = args[1] else: url = clipboard.get() #print(url) git_download(url) def git_download_from_sharesheet(): if appex.is_running_extension(): #unquote=requests.utils.unquote #urlparse=requests.utils.urlparse url = appex.get_url() #print(url) git_download(url) else: # Error handling... print('''===== * In Safari browser, navigate to a GitHub repo or Gist of interest. * Tap 'Open in...' icon in top right of Safai window. * Tap 'Run Pythonista Script'. * Pick this script and tap the run button. * When you return to Pythonista the files should be in '~/Documents/Downloaded from Github/'.''') def dlProgress(filename, count, blockSize, totalSize): if count*blockSize > totalSize: percent=100 else: percent = max(min(int(count*blockSize*100/totalSize),100),0) sys.stdout.write("\r" + filename + "...%d%%" % percent) sys.stdout.flush() def git_download(url): base = 'https://codeload.github.com' archive = 'zip' m = extract_git_id(url) if m: g = m.groupdict() if not g['branch']: g['branch'] = 'master' u = '/'.join((base,g['user'],g['repo'],archive, g['branch'])) #print u #console.hud_alert('Downloading Github repo ...' + u) console.hud_alert('Starting, please wait.') console.show_activity() try: with tempfile.NamedTemporaryFile(mode='w+b',suffix='.zip') as f: console.hud_alert('Downloading the zip.') urllib.urlretrieve(u,f.name,reporthook=functools.partial(dlProgress,u)) z = zipfile.ZipFile(f) githubpath = os.path.expanduser('~/Documents/Downloaded from Github/') if not os.path.exists(githubpath): os.mkdir(githubpath) z.extractall(path = githubpath) console.hud_alert('Extracting zip.') print z.namelist() except: print('git url did not return zip file') console.hud_alert('Files saved in "Downloaded from Github" directory.') console.hud_alert('All done.') else: print('could not determine repo url from clipboard or argv') if __name__=='__main__': #git_download_from_args(sys.argv) git_download_from_sharesheet()
-
@mrcoxall , I just had a look to see if you were in on this discussion-
https://forum.omz-software.com/topic/2382/git-or-gist-workflow-for-pythonista/35
Maybe you seen it. Not sure. But @ccc approach is pretty nice. Granted you need another app (working-copy) and it's a few steps.Not a one click solution. But It can be 2 way solution (I tested it). Also via working-copy you have a real link back to the source. But the solution is pretty fast and memorable for repeating over and over. I just mention it because it's helped me tremendously. It takes me around 20-30 seconds to the the gist/repo into working-copy then using @ccc apex script to move it into Pythonista.
Anyway, just a thought. Personally, I prefer the structure over the speed.