├── GitHubGet.py └── README.md /GitHubGet.py: -------------------------------------------------------------------------------- 1 | # download an entire github repo. 2 | # 3 | # either copy the url to clipboard, and run script, or run following bookmarklet. 4 | # will unzip to repo-branch (so be careful if downloading same branch name from multiple users) 5 | # 6 | ## javascript:(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href='pythonista://GitHubGet?action=run&argv='+document.location.href;%7D)(); 7 | 8 | 9 | import urllib,zipfile,sys, clipboard, functools, re, os, tempfile 10 | 11 | def extract_git_id(git): 12 | print git 13 | m = re.match((r'^http(s?)://([\w-]*\.)?github\.com/(?P[\w-]+)/(?P[\w-]*)' 14 | '((/tree|/blob)/(?P[\w-]*))?'), git) 15 | # print m.groupdict() 16 | return m 17 | 18 | def git_download_from_args(args): 19 | if len(args) == 2: 20 | url = args[1] 21 | else: 22 | url = clipboard.get() 23 | git_download(url) 24 | 25 | 26 | def dlProgress(filename, count, blockSize, totalSize): 27 | if count*blockSize > totalSize: 28 | percent=100 29 | else: 30 | percent = max(min(int(count*blockSize*100/totalSize),100),0) 31 | sys.stdout.write("\r" + filename + "...%d%%" % percent) 32 | sys.stdout.flush() 33 | 34 | def git_download(url): 35 | base='https://codeload.github.com' 36 | archive='zip' 37 | m=extract_git_id(url) 38 | if m: 39 | g=m.groupdict() 40 | if not g['branch']: 41 | g['branch']='master' 42 | 43 | u= '/'.join((base,g['user'],g['repo'],archive, g['branch'])) 44 | #print u 45 | try: 46 | with tempfile.NamedTemporaryFile(mode='w+b',suffix='.zip') as f: 47 | urllib.urlretrieve(u,f.name,reporthook=functools.partial(dlProgress,u)) 48 | z=zipfile.ZipFile(f) 49 | z.extractall() 50 | print z.namelist() 51 | except: 52 | print('git url did not return zip file') 53 | else: 54 | print('could not determine repo url from clipboard or argv') 55 | 56 | if __name__=='__main__': 57 | git_download_from_args(sys.argv) 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GitHubGet 2 | ========= 3 | 4 | Quick script to zip and download a repo from github, for those afraid of shellista 5 | 6 | 7 | Two ways to use: 8 | 1) copy url into clipboard, and run 9 | 2). Use bookmarklet 10 | javascript:(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href='pythonista://GitHubGet?action=run&argv='+document.location.href;%7D)(); 11 | 12 | In either case, just go to main github repo page, and/or choose the branch you want cloned. Script should be able to figure out user, repo, and branch, downloads the zip of the repo to a temp file, unzips into main script folder (will be under folder named repo-branch, for instance GitHubGet-master/ for this repo). 13 | 14 | This script makes no attempt to check if you've downloaded a repo before, nor does it distinguish the folder based on username. 15 | --------------------------------------------------------------------------------