Skip to content

Instantly share code, notes, and snippets.

@0xquad
Last active March 3, 2016 04:01
Show Gist options
  • Save 0xquad/34fc10098cc750a04d1a to your computer and use it in GitHub Desktop.
Save 0xquad/34fc10098cc750a04d1a to your computer and use it in GitHub Desktop.
Simple Gist command line tool
#!/usr/bin/env python3
#
# Simple Gist command line tool. Only support listing the user's gist for now.
#
# Copyright (c) 2015, Alexandre Hamelin <alexandre.hamelin gmail.com>
import requests
import json
import os
from collections import namedtuple
if __name__ == '__main__':
api_token = os.environ['GIST_API_TOKEN']
resp = requests.get('https://api.github.com/gists',
auth=('none', api_token))
gists = json.loads(resp.content.decode(resp.encoding))
# with open('gists.json', 'r') as fp:
# gists = json.load(fp)
Gist = namedtuple('Gist', gists[0].keys())
gists = map(lambda g: Gist(*g.values()), gists)
for g in gists:
print(g.git_pull_url.replace('https://', 'git@').replace('/', ':'),
g.description)
print('Remaining queries:', resp.headers['X-RateLimit-Remaining'])
# print(', '.join(filter(lambda a: not a.startswith('__'), dir(Gist))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment