-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetOrgRepos.py
40 lines (36 loc) · 1.21 KB
/
getOrgRepos.py
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
import requests
import json
import sys
import os
project = sys.argv[1]
url = "https://gitee.com/api/v5/orgs/{}/repos".format(project)
playload = {
"type": "all",
"page": 1,
"per_page": 100,
"access_token": "319cf70a2aee7f8791427d0a8044890d"
}
outf = open(os.path.join('.', 'data', project), 'w')
currentPage = 1
response = requests.get(url=url, params=playload)
headers = response.headers
totalPage = int(headers['Total_page'])
totalCount = int(headers['Total_count'])
print('Total page: {}, Total count: {}'.format(totalPage, totalCount))
currentCount = 0
for repo in response.json():
if 'html_url' in repo and repo['html_url'] != '':
outf.write(repo['html_url'] + '\n')
currentCount += 1
print('Current page: {}, Current count: {}'.format(currentPage, currentCount))
while (currentPage != totalPage):
currentPage += 1
playload["page"] = currentPage
response = requests.get(url=url, params=playload)
for repo in response.json():
if 'html_url' in repo and repo['html_url'] != '':
outf.write(repo['html_url'] + '\n')
currentCount += 1
print('Current page: {}, Current count: {}'.format(currentPage, currentCount))
print('Finished!')
outf.close()