Skip to content

Instantly share code, notes, and snippets.

@fedir
Forked from nicerobot/backup.sh
Last active April 21, 2024 21:31
Show Gist options
  • Select an option

  • Save fedir/5466075 to your computer and use it in GitHub Desktop.

Select an option

Save fedir/5466075 to your computer and use it in GitHub Desktop.

Revisions

  1. fedir revised this gist Jul 23, 2014. 1 changed file with 32 additions and 12 deletions.
    44 changes: 32 additions & 12 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,44 @@
    #!/usr/bin/env python
    # Clone or update all a user's gists
    # curl -ks https://gist.githubusercontent.com/fedir/5466075/raw/gist-backup.py | USER=fedir python
    # 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']

    u = urlopen('https://api.github.com/users/' + USER + '/gists?per_page=100')
    gists = json.load(u)
    startd = os.getcwd()
    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)

    for gist in gists:
    gistd = gist['id']
    if os.path.isdir(gistd):
    os.chdir(gistd)
    call(['git', 'pull', 'git://gist.github.com/' + gistd + '.git'])
    os.chdir(startd)
    else:
    call(['git', 'clone', 'git://gist.github.com/' + gistd + '.git'])
    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
  2. fedir revised this gist Apr 14, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    import os
    USER = os.environ['USER']

    u = urlopen('https://api.github.com/users/' + USER + '/gists')
    u = urlopen('https://api.github.com/users/' + USER + '/gists?per_page=100')
    gists = json.load(u)
    startd = os.getcwd()

    @@ -21,4 +21,4 @@
    call(['git', 'pull', 'git://gist.github.com/' + gistd + '.git'])
    os.chdir(startd)
    else:
    call(['git', 'clone', 'git://gist.github.com/' + gistd + '.git'])
    call(['git', 'clone', 'git://gist.github.com/' + gistd + '.git'])
  3. fedir revised this gist Apr 14, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    #!/usr/bin/env python
    # Clone or update all a user's gists
    # curl -ks https://raw.github.com/gist/5466075/gist-backup.py | python
    # curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python
    # curl -ks https://gist.githubusercontent.com/fedir/5466075/raw/gist-backup.py | USER=fedir python
    # USER=fedir python gist-backup.py

    import json
  4. fedir revised this gist Apr 26, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    # Clone or update all a user's gists
    # curl -ks https://raw.github.com/gist/5466075/gist-backup.py | python
    # curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python
    # USER=fedir python gist-backup.py

    import json
    import urllib
  5. fedir revised this gist Apr 26, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env python
    # Clone or update all a user's gists
    # curl -ks https://raw.github.com/gist/1622504/gist-backup.py | python
    # curl -ks https://raw.github.com/gist/1622504/gist-backup.py | USER=nicerobot python
    # curl -ks https://raw.github.com/gist/5466075/gist-backup.py | python
    # curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python

    import json
    import urllib
    @@ -10,12 +10,12 @@
    import os
    USER = os.environ['USER']

    u = urlopen('https://gist.github.com/api/v1/json/gists/' + USER)
    gists = json.load(u)['gists']
    u = urlopen('https://api.github.com/users/' + USER + '/gists')
    gists = json.load(u)
    startd = os.getcwd()

    for gist in gists:
    gistd = gist['repo']
    gistd = gist['id']
    if os.path.isdir(gistd):
    os.chdir(gistd)
    call(['git', 'pull', 'git://gist.github.com/' + gistd + '.git'])
  6. @nicerobot nicerobot revised this gist Jan 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/usr/bin/env python
    # Clone o update all a user's gists
    # Clone or update all a user's gists
    # curl -ks https://raw.github.com/gist/1622504/gist-backup.py | python
    # curl -ks https://raw.github.com/gist/1622504/gist-backup.py | USER=nicerobot python

  7. @nicerobot nicerobot revised this gist Jan 16, 2012. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/usr/bin/env python
    # Git clone all my gists
    # Clone o update all a user's gists
    # curl -ks https://raw.github.com/gist/1622504/gist-backup.py | python
    # curl -ks https://raw.github.com/gist/1622504/gist-backup.py | USER=nicerobot python

    import json
    import urllib
    @@ -10,6 +12,13 @@

    u = urlopen('https://gist.github.com/api/v1/json/gists/' + USER)
    gists = json.load(u)['gists']
    startd = os.getcwd()

    for gist in gists:
    call(['git', 'clone', 'git://gist.github.com/' + gist['repo'] + '.git'])
    gistd = gist['repo']
    if os.path.isdir(gistd):
    os.chdir(gistd)
    call(['git', 'pull', 'git://gist.github.com/' + gistd + '.git'])
    os.chdir(startd)
    else:
    call(['git', 'clone', 'git://gist.github.com/' + gistd + '.git'])
  8. @joneskoo joneskoo created this gist Dec 15, 2011.
    15 changes: 15 additions & 0 deletions gist-backup.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/usr/bin/env python
    # Git clone all my gists

    import json
    import urllib
    from subprocess import call
    from urllib import urlopen
    import os
    USER = os.environ['USER']

    u = urlopen('https://gist.github.com/api/v1/json/gists/' + USER)
    gists = json.load(u)['gists']

    for gist in gists:
    call(['git', 'clone', 'git://gist.github.com/' + gist['repo'] + '.git'])