Skip to content

Instantly share code, notes, and snippets.

@t1m0thyj
Created October 21, 2020 05:11
Show Gist options
  • Save t1m0thyj/1e78c6fe8e4113068c643eb9ad083d66 to your computer and use it in GitHub Desktop.
Save t1m0thyj/1e78c6fe8e4113068c643eb9ad083d66 to your computer and use it in GitHub Desktop.
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