Skip to content

Instantly share code, notes, and snippets.

@drichardson
Created December 7, 2020 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drichardson/68dc5cd78cab5e736df6b0f5aa6b2d2d to your computer and use it in GitHub Desktop.
Save drichardson/68dc5cd78cab5e736df6b0f5aa6b2d2d to your computer and use it in GitHub Desktop.
List github gpg public keys for a user
#!/usr/bin/python3
import json
import sys
import urllib.request
import os
scriptname=os.path.basename(__file__)
usage=f'''Missing username.
USAGE
{scriptname} username
EXAMPLES
List drichardson's gpg public keys:
{scriptname} drichardson
View drichardson's gpg public keys with GnuPG:
{scriptname} drichardson | gpg
Import drichardson's gpg public keys to GnuPG:
{scriptname} drichardson | gpg --import
'''
if len(sys.argv) < 2:
sys.stderr.write(usage)
sys.exit(1)
username=sys.argv[1]
req = urllib.request.Request(f'https://api.github.com/users/{username}/gpg_keys')
req.add_header('Accept', 'application/vnd.github.v3+json')
with urllib.request.urlopen(req) as f:
for entry in json.load(f):
print(entry['raw_key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment