Created
October 21, 2020 05:11
-
-
Save t1m0thyj/1e78c6fe8e4113068c643eb9ad083d66 to your computer and use it in GitHub Desktop.
This file contains 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 requests | |
import subprocess | |
GITHUB_API = "https://api.github.com" | |
GITHUB_PAT = "<personal-access-token>" | |
OLD_USER = "<username>" | |
NEW_USER = "<username>" | |
gists = requests.get(GITHUB_API + "/users/" + OLD_USER + "/gists").json() | |
for gist in gists: | |
gist_id = gist["id"] | |
git_pull_url = gist["git_pull_url"] | |
subprocess.call("git clone " + git_pull_url, shell=True) | |
response = requests.post(GITHUB_API + "/gists", json={ | |
"files": { | |
"temp.txt": { | |
"content": "hello world" | |
} | |
}, | |
"public": True | |
}, auth=(NEW_USER, GITHUB_PAT)).json() | |
git_push_url = response["git_push_url"] | |
subprocess.call("cd " + gist_id + " && git remote set-url origin " + git_push_url + " && git push -u origin master --force && cd ..", shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment