Created
February 23, 2013 12:22
-
-
Save maddievision/5019580 to your computer and use it in GitHub Desktop.
Gist Getter for Pythonista
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will prompt a URL to grab gist files, it will pre-populate with current clipboard contents. | |
# You can also just enter the gist ID by itself. | |
# Will write each file by its filename | |
import sys | |
import requests | |
import os | |
import console | |
import clipboard | |
import json | |
def codeget(url): | |
r = requests.get('https://api.github.com/gists/%s' % os.path.split(url.strip().split(" ")[0])[-1]) | |
f = json.loads(r.text) | |
for x,v in f['files'].iteritems(): | |
with open(v['filename'],'w') as ip: | |
ip.write(v['content']) | |
print 'Wrote %d chars to %s' % (len(v['content']),v['filename']) | |
if __name__ == '__main__': | |
a = console.input_alert('URL','Enter URL',clipboard.get()) | |
codeget(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment