Skip to content

Instantly share code, notes, and snippets.

@selimslab
Forked from leoloobeek/get_gists.py
Last active December 23, 2023 15:52
Show Gist options
  • Select an option

  • Save selimslab/958e2255a105f9a3f4b421896bce715d to your computer and use it in GitHub Desktop.

Select an option

Save selimslab/958e2255a105f9a3f4b421896bce715d to your computer and use it in GitHub Desktop.

Revisions

  1. selimslab revised this gist Jun 18, 2021. No changes.
  2. selimslab revised this gist Sep 25, 2020. 1 changed file with 32 additions and 10 deletions.
    42 changes: 32 additions & 10 deletions get_gists.py
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,38 @@
    # first: mkdir user && cd user && cp /path/to/get_gists.py .
    # python3 get_gists.py user
    import requests
    import sys
    from subprocess import call
    import json
    import os
    import requests

    user = sys.argv[1]

    r = requests.get('https://api.github.com/users/{0}/gists'.format(user))
    def download_gists(gists: list):
    for gist in gists:
    call(["git", "clone", gist["git_pull_url"]])

    #  name of the first file in the gist
    new_folder_name = sorted(list(gist.get("files", {}).keys()))[0].split(".")[0]

    os.rename(gist["id"], new_folder_name)

    description_file = os.path.join(new_folder_name, "description.txt")
    with open(description_file, "w") as f:
    f.write(f"{gist['description']}\n")

    for i in r.json():
    call(['git', 'clone', i['git_pull_url']])

    description_file = './{0}/description.txt'.format(i['id'])
    with open(description_file, 'w') as f:
    f.write('{0}\n'.format(i['description']))
    def visit_pages(user: str):
    next_page = True
    page = 1
    while next_page:
    url = f"https://api.github.com/users/{user}/gists?page={page}"
    r = requests.get(url)

    if not len(r.json()):
    next_page = False
    else:
    page += 1

    download_gists(r.json())


    user = sys.argv[1]
    visit_pages(user)
  3. @leoloobeek leoloobeek created this gist Apr 26, 2017.
    16 changes: 16 additions & 0 deletions get_gists.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # first: mkdir user && cd user && cp /path/to/get_gists.py .
    # python3 get_gists.py user
    import requests
    import sys
    from subprocess import call

    user = sys.argv[1]

    r = requests.get('https://api.github.com/users/{0}/gists'.format(user))

    for i in r.json():
    call(['git', 'clone', i['git_pull_url']])

    description_file = './{0}/description.txt'.format(i['id'])
    with open(description_file, 'w') as f:
    f.write('{0}\n'.format(i['description']))