是否有API调用或任何我未能推翻的脚本会将我的所有Gists从Github拉到外部git repo或只返回一个他们的名字列表?我知道每一个都是一个单独的git repo,所以我假设我能做的最好就是获得后者,然后脚本将所有这些都放到我的本地盒子上.
编辑1:我知道将git repos从一个服务拉到另一个服务,我特别想找到411收集我拥有的所有Gists,私有和公共的权威列表的人.我也认为这可能对其他人有用.它不是关于迁移,而是备份策略...各种各样的.
编辑2:所以,似乎这可能是不可能的.我显然没有足够的谷歌搜索更新的Github/Gist API.其他API调用使用简单的curl命令,但不适用于Gist的v1 API.尽管如此,API仍然为所有私人和公共Gist提供了 TBD ,所以我认为除非一个开明的灵魂勾起了一个新的东西,否则就会把它放在整个事物上.
$ curl http://github.com/api/v2/json/repos/show/alharaka
{"repositories":[{"url":"https://github.com/alharaka/babushka","has_wiki":true,"homepage":"http:
... # tons of more output
echo $?
0
$
Run Code Online (Sandbox Code Playgroud)
这个不太热.
$ curl https://gist.github.com/api/v1/:format/gists/:alharaka
$ echo $?
0
$
Run Code Online (Sandbox Code Playgroud)
编辑3:在我被问及之前,我发现API版本存在差异; 这个"精彩的黑客"也没有帮助.虽然还很酷.
$ curl https://gist.github.com/api/v2/:format/gists/:alharaka # Notice v2 instead of v1
$ echo $?
0
$
Run Code Online (Sandbox Code Playgroud)
Kor*_*tor 19
GitHub API的第3版允许以一种非常简单的方式:
https://api.github.com/users/koraktor/gists
Run Code Online (Sandbox Code Playgroud)
为您提供用户所有要点的列表,该列表提供了各种URL,包括各个Gists的API URL
https://api.github.com/gists/921286
Run Code Online (Sandbox Code Playgroud)
请参阅Gists API v3文档.
Fed*_*TIK 14
在nictoobot脚本的API v3中进行了改编,最初是为API v1编写的:
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
import os
import math
USER = os.environ['USER']
perpage=30.0
userurl = urlopen('https://api.github.com/users/' + USER)
public_gists = json.load(userurl)
gistcount = public_gists['public_gists']
print "Found gists : " + str(gistcount)
pages = int(math.ceil(float(gistcount)/perpage))
print "Found pages : " + str(pages)
f=open('./contents.txt', 'w+')
for page in range(pages):
pageNumber = str(page + 1)
print "Processing page number " + pageNumber
pageUrl = 'https://api.github.com/users/' + USER + '/gists?page=' + pageNumber + '&per_page=' + str(int(perpage))
u = urlopen (pageUrl)
gists = json.load(u)
startd = os.getcwd()
for gist in gists:
gistd = gist['id']
gistUrl = 'git://gist.github.com/' + gistd + '.git'
if os.path.isdir(gistd):
os.chdir(gistd)
call(['git', 'pull', gistUrl])
os.chdir(startd)
else:
call(['git', 'clone', gistUrl])
if gist['description'] == None:
description = ''
else:
description = gist['description'].encode('utf8').replace("\r",' ').replace("\n",' ')
print >> f, gist['id'], gistUrl, description
Run Code Online (Sandbox Code Playgroud)
一个版本的@Fedir脚本,它解释了Github的分页(如果你有几百个主题):
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
import os
import math
USER = os.environ['USER']
perpage=30.0
userurl = urlopen('https://api.github.com/users/' + USER)
public_gists = json.load(userurl)
gistcount = public_gists['public_gists']
print "Found gists : " + str(gistcount)
pages = int(math.ceil(float(gistcount)/perpage))
print "Found pages : " + str(pages)
f=open('./contents.txt', 'w+')
for page in range(pages):
pageNumber = str(page + 1)
print "Processing page number " + pageNumber
pageUrl = 'https://api.github.com/users/' + USER + '/gists?page=' + pageNumber + '&per_page=' + str(int(perpage))
u = urlopen (pageUrl)
gists = json.load(u)
startd = os.getcwd()
for gist in gists:
gistd = gist['id']
gistUrl = 'git://gist.github.com/' + gistd + '.git'
if os.path.isdir(gistd):
os.chdir(gistd)
call(['git', 'pull', gistUrl])
os.chdir(startd)
else:
call(['git', 'clone', gistUrl])
Run Code Online (Sandbox Code Playgroud)
根据这个答案中的提示,我编写了这个简单的Python脚本,它对我有用。
这是非常最少的代码,几乎没有任何错误检查,并将所有用户的要点克隆到当前目录中。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Clone all gists of GitHub username given on the command line."""
import subprocess
import sys
import requests
if len(sys.argv) > 1:
gh_user = sys.argv[1]
else:
print("Usage: clone-gists.py <GitHub username>")
sys.exit(1)
req = requests.get('https://api.github.com/users/%s/gists' % gh_user)
for gist in req.json():
ret = subprocess.call(['git', 'clone', gist['git_pull_url']])
if ret != 0:
print("ERROR cloning gist %s. Please check output." % gist['id'])
Run Code Online (Sandbox Code Playgroud)
请参阅https://gist.github.com/SpotlightKid/042491a9a2987af04a5a了解也可以处理更新的版本。
| 归档时间: |
|
| 查看次数: |
5730 次 |
| 最近记录: |