Last active
May 26, 2020 14:43
-
-
Save bkamapantula/5526568152855f7b44ecd4fd29551451 to your computer and use it in GitHub Desktop.
Create GitHub Gist with Python requests
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
# this example is adapted from https://stackoverflow.com/a/50704456 | |
import requests, json | |
# handler below is a Gramex FunctionHandler object | |
# ref: https://learn.gramener.com/guide/functionhandler/ | |
# three arguments are passed from the user input: ?js=, ?json=, and ?md= | |
data = json.dumps({ | |
"public":"true", | |
"files": { | |
"index.js": { | |
"content": handler.get_argument('js') | |
}, | |
"data.json": { | |
"content": handler.get_argument('json') | |
}, | |
"README.md": { | |
"content": handler.get_argument('md') | |
} | |
} | |
}) | |
# GITHUB_ACCESS_TOKEN is a personal access token created under my profile -> developer settings | |
response = requests.post('https://api.github.com/gists', data=data, auth=('bkamapantula', GITHUB_ACCESS_TOKEN)) | |
return json.dumps(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment