Last active
August 29, 2015 14:26
-
-
Save githubutilities/92f7ff626b873ccc0e72 to your computer and use it in GitHub Desktop.
Generating .gitignore file using github/gitignore
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
| #/usr/bin/env python | |
| import urllib2,json | |
| from os.path import splitext | |
| # load file list | |
| response = urllib2.urlopen('https://api.github.com/repos/github/gitignore/contents/') | |
| files = json.load(response) | |
| def list(): | |
| for file in files: | |
| basename = file["name"] | |
| filename = splitext(basename)[0] | |
| extension = splitext(basename)[1] | |
| if '' != extension: | |
| print filename | |
| def download(language): | |
| for file in files: | |
| basename = file["name"] | |
| filename = splitext(basename)[0] | |
| if filename.lower() == language.lower(): | |
| response = urllib2.urlopen(file["download_url"]) | |
| return response.read() | |
| return '' | |
| import sys | |
| cmd = sys.argv[1] | |
| if "list" == cmd: | |
| list() | |
| else: | |
| langs = cmd.split(',') | |
| for lang in langs: | |
| gitignore = download(lang) | |
| if '' != gitignore: | |
| print "# " + lang | |
| print gitignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment