Skip to content

Instantly share code, notes, and snippets.

@jfach
Last active June 10, 2016 20:05
Show Gist options
  • Save jfach/ec85c6550cf9fc99e3a708bd45ec6a8c to your computer and use it in GitHub Desktop.
Save jfach/ec85c6550cf9fc99e3a708bd45ec6a8c to your computer and use it in GitHub Desktop.
generate PAT for github
GITHUB_API = 'https://api.github.com'
import requests
import getpass
import json
from urlparse import urljoin
def main():
#
# User Input
#
username = raw_input('github username: ')
password = getpass.getpass('github password: ')
note = raw_input('Label: ') # DONT LEAVE THIS FIELD BLANK!!!
#
# Compose Request
#
url = urljoin(GITHUB_API, 'authorizations')
payload = {}
if note:
payload['note'] = note
res = requests.post(
url,
auth = (username, password),
data = json.dumps(payload),
)
#
# Parse Response
#
j = json.loads(res.text)
token = j['token']
print token
return token
if __name__ == '__main__':
main()
@jfach
Copy link
Author

jfach commented Jun 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment