- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplaygithubgists.py
More file actions
Latest commit
40 lines (32 loc) · 1.03 KB
/
Copy pathdisplaygithubgists.py
File metadata and controls
40 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
importsys
importjson
importurllib
fromsubprocessimportcall
fromurllibimporturlopen
importos
importmath
# Get the username from command line args
iflen(sys.argv) !=2:
print"\nUsername Required. Example: python DisplayGitHubGists.py DForshner";
sys.exit()
user=str(sys.argv[1])
print ("\nGetting gists for: "+user)
# Get total number of gists
userurl=urlopen('https://api.github.com/users/'+user)
public_gists=json.load(userurl)
gistcount=public_gists['public_gists']
print ("Getting "+str(gistcount) +" gists\n")
# Get total number of gists pages
perpage=30.0
pages=int(math.ceil(float(gistcount)/perpage))
# Get gists from each page
forpageinrange(pages):
u=urlopen('https://api.github.com/users/'+user+'/gists?page='+str(page) +'&per_page='+str(int(perpage)))
gists=json.load(u)
startd=os.getcwd()
# Display info about each gist
forgistingists:
gistid=gist['id']
gistdesc=gist['description']
print (gistid+" - "+gistdesc)