def create_private_gist(config, main_github_token, filename, content, description):
g = Github(main_github_token)
g_user = g.get_user()
gist = g_user.create_gist(False, {filename: github.InputFileContent(content)}, description)
# gists have a list of files associated with them, we just want the first one
# gist.files = {'filename': GistFile(filename), ...}
gist_file = [x for x in gist.files.values()][0]
config["gist_raw_contents_url"] = gist_file.raw_url
# The structure of the url is:
# https://gist.githubusercontent.com/<username>/<gist guid>/raw/<file guid>/<filename.txt>
#
# Since we're only uploading one file and we want to make the URL as concise as possible,
# it turns out we can actually trim off everything after /raw/ and it'll still give us what
# we want.
config["gist_raw_contents_url"] = config["gist_raw_contents_url"].split("/raw/")[0] + "/raw"
print("[*] Private gist content at:")
print("- %s" % config["gist_raw_contents_url"])
return config
# Return the content that will placed in the private gist
评论列表
文章目录