Last active
February 1, 2022 01:23
-
-
Save sophiezhng/7c1a20c859c2a7a33867ff2c3afb0601 to your computer and use it in GitHub Desktop.
Edit your GitHub profile bio programmatically using Python and the GitHub API
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
import json | |
import requests | |
from getpass import getpass | |
# Login to GitHub and go to Settings > Developer settings > Personal access tokens and generate a new token. | |
# For scope click the user checkmark and generate token. | |
# Save it elsewhere as after you close the tab you will not be able to see it again on your profile. | |
api_token = getpass('API Token: ') | |
h = {'Accept': 'application/vnd.github.v3+json', | |
'Authorization': 'token ' + api_token} | |
def main(): | |
get_bio("Old bio: ") | |
new_bio = input("Enter new bio: ") | |
bio_patch = requests.patch('https://api.github.com/user', json = {'bio': new_bio}, headers = h) | |
print ("Status: ", bio_patch.status_code) | |
get_bio("New bio: ") | |
def get_bio(context): | |
r = requests.get('https://api.github.com/user', headers=h) | |
json = r.json() | |
print(context + json["bio"]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment