Skip to content

Instantly share code, notes, and snippets.

@tyrelsouza
Last active August 29, 2015 14:21
Show Gist options
  • Save tyrelsouza/12516139976bceb4a6b0 to your computer and use it in GitHub Desktop.
Save tyrelsouza/12516139976bceb4a6b0 to your computer and use it in GitHub Desktop.
Import Keybase Keys you are Tracking into GnuPG
import gnupg
import urllib
from subprocess import Popen, PIPE
import os
from pprint import pprint
def get_names():
p = Popen(['keybase', 'list-tracking'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
rc = p.returncode
if rc == 0:
return output.split()
return []
def get_keyfile(username):
URL = "https://keybase.io/{username}/key.asc".format(username=username)
asc = urllib.urlopen(URL).read()
return asc
def import_keyfiles(keyfile):
gpg = gnupg.GPG(gnupghome=os.path.join(os.path.expanduser('~'),".gnupg"))
import_result = gpg.import_keys(keyfile)
return import_result.results
def main():
results = []
names = get_names() # Assuming you're tracking at least one person. Otherwise why would you run this?
keyfiles = [get_keyfile(name) for name in names]
for result in keyfiles:
results.extend(import_keyfiles(result))
pprint(results)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment