-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_badges.py
More file actions
270 lines (242 loc) · 9.6 KB
/
get_badges.py
File metadata and controls
270 lines (242 loc) · 9.6 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
"""
Get package information
Searches for packages on pypi with SciKit-Surgery in the name, then
gets some statistics for them.
"""
import contextlib
import os.path
import requests
from requests.exceptions import SSLError
import json
from sksurgerystats.common import (
get_packages,
get_package_information,
update_package_information,
)
if __name__ == "__main__":
packages = get_packages()
badges = {
"total": 0,
"ci_badge": 0,
"coverage_badge": 0,
"docs_badge": 0,
"codeclimate_badge": 0,
"pepy_downloads_badge": 0,
"syntek_package_health_badge": 0,
}
for package in packages:
print("Getting badges for ", package)
ci_badge = get_package_information(package, "ci_badge")
ci_target = get_package_information(package, "ci_target")
coverage_badge = get_package_information(package, "coverage_badge")
coverage_target = get_package_information(package, "coverage_target")
docs_badge = get_package_information(package, "docs_badge")
docs_target = get_package_information(package, "docs_target")
codeclimate_badge = get_package_information(package, "codeclimate_badge")
codeclimate_target = get_package_information(package, "codeclimate_target")
pepy_downloads_badge = get_package_information(package, "pepy_downloads_badge")
pepy_downloads_target = get_package_information(
package,
"pepy_downloads_target",
)
syntek_package_health_badge = get_package_information(
package,
"syntek_package_health_badge",
)
syntek_package_health_target = get_package_information(
package,
"syntek_package_health_target",
)
homepage = get_package_information(package, "home_page")
if homepage is not None:
project_name = homepage
split_name = project_name.split("/")
badges["total"] += 1
with contextlib.suppress(IndexError):
project_name = split_name[-2] + "/" + split_name[-1]
if ci_badge is None:
ci_badge = str(
homepage + "/workflows/.github/workflows/ci.yml/badge.svg",
)
if ci_target is None:
ci_target = str(homepage + "/actions")
if coverage_badge is None:
coverage_badge = str(
"https://coveralls.io/repos/github/"
+ project_name
+ "/badge.svg?branch=master&service=github",
)
if coverage_target is None:
coverage_target = str(
"https://coveralls.io/github/" + project_name + "?branch=master",
)
if docs_badge is None:
docs_badge = str(
"https://readthedocs.org/projects/"
+ package
+ "/badge/?version=latest",
)
if docs_target is None:
docs_target = str(
"https://" + package + ".readthedocs.io/en/latest/?badge=latest",
)
if codeclimate_badge is None:
# doesn't seem a straight forward way here
pass
if codeclimate_target is None:
codeclimate_target = str(
"https://codeclimate.com/github/" + project_name,
)
if pepy_downloads_badge is None:
pepy_downloads_badge = str("https://static.pepy.tech/badge/" + package)
# always update this
if pepy_downloads_target is None:
pepy_downloads_target = str(
"https://pepy.tech/projects/" + package)
if syntek_package_health_badge is None:
syntek_package_health_badge = str(
"https://snyk.io/advisor/python/" + package + "/badge.svg",
)
if syntek_package_health_target is None:
syntek_package_health_target = str(
"https://snyk.io/advisor/python/" + package,
)
# check and update ci
if ci_badge is not None:
req = requests.get(ci_badge)
if req.status_code == 200:
badges["ci_badge"] = badges["ci_badge"] + 1
update_package_information(
package,
"ci_badge",
ci_badge,
overwrite=True,
)
if ci_target is not None:
req = requests.get(ci_target)
if req.status_code == 200:
update_package_information(
package,
"ci_target",
ci_target,
overwrite=True,
)
# cheek and update coverage
if coverage_badge is not None:
req = requests.get(coverage_badge)
if req.status_code == 200:
badges["coverage_badge"] = badges["coverage_badge"] + 1
update_package_information(
package,
"coverage_badge",
coverage_badge,
overwrite=True,
)
if coverage_target is not None:
req = requests.get(coverage_target)
if req.status_code == 200:
update_package_information(
package,
"coverage_target",
coverage_target,
overwrite=True,
)
if docs_badge is not None:
try:
try:
req = requests.get(docs_badge)
except:
req = requests.get(docs_badge, verify=False)
# This conditional protects against some of the certificate errors we got with especially excluded libraries
except SSLError as e:
print("SSL version or cipher mismatch error occurred:", e)
# Handle the error or continue with other operations
pass
if req.status_code == 200:
badges["docs_badge"] += 1
update_package_information(
package,
"docs_badge",
docs_badge,
overwrite=False,
)
# This conditional protects against some of the certificate errors we got with especially excluded libraries
if docs_target is not None:
try:
try:
req = requests.get(docs_target)
except:
req = requests.get(docs_target, verify=False)
except SSLError as e:
print("SSL version or cipher mismatch error occurred:", e)
# Handle the error or continue with other operations
pass
if req.status_code == 200:
update_package_information(
package,
"docs_target",
docs_target,
overwrite=True,
)
# check and update codeclimate
if codeclimate_badge is not None:
req = requests.get(codeclimate_badge)
if req.status_code == 200:
badges["codeclimate_badge"] += 1
update_package_information(
package,
"codeclimate_badge",
codeclimate_badge,
overwrite=True,
)
if codeclimate_target is not None:
req = requests.get(codeclimate_target)
if req.status_code == 200:
update_package_information(
package,
"codeclimate_target",
codeclimate_target,
overwrite=True,
)
# check and update pepy_downloads
if pepy_downloads_badge is not None:
req = requests.get(pepy_downloads_badge)
if req.status_code == 200:
badges["pepy_downloads_badge"] += 1
update_package_information(
package,
"pepy_downloads_badge",
pepy_downloads_badge,
overwrite=True,
)
if pepy_downloads_target is not None:
req = requests.get(pepy_downloads_target)
if req.status_code == 200:
update_package_information(
package,
"pepy_downloads_target",
pepy_downloads_target,
overwrite=True,
)
# check and update syntek_package_health
if syntek_package_health_badge is not None:
req = requests.get(syntek_package_health_badge)
if req.status_code == 200:
badges["syntek_package_health_badge"] += 1
update_package_information(
package,
"syntek_package_health_badge",
syntek_package_health_badge,
overwrite=True,
)
if syntek_package_health_target is not None:
req = requests.get(syntek_package_health_target)
if req.status_code == 200:
update_package_information(
package,
"syntek_package_health_target",
syntek_package_health_target,
overwrite=True,
)
with open("libraries/available_badges.json", "w") as fileout:
json.dump(badges, fileout, default=str)