Skip to content

Instantly share code, notes, and snippets.

@mdecourse
Created January 19, 2022 07:26
Show Gist options
  • Save mdecourse/6605ff991784e172fb8c6c3693483a32 to your computer and use it in GitHub Desktop.
Save mdecourse/6605ff991784e172fb8c6c3693483a32 to your computer and use it in GitHub Desktop.
Get data from public gist
import json
from urllib.request import urlopen
import os
import math
USER = "mdecourse"
#perpage=30.0
perpage = 100.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 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:
#print(gist['description'], gist.keys())
#print(gist['description'], gist['created_at'], gist['files'])
files = gist['files']
#print(files)
for i in files.keys():
print(files[i]['filename'], files[i]['size'])
print(files[i]['raw_url'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment