-
Notifications
You must be signed in to change notification settings - Fork 27
/
utils.py
92 lines (72 loc) · 2.38 KB
/
utils.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
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
import datetime
import json
import pytz
import requests
BASE_URL = "https://pypi.org/pypi"
DEPRECATED_PACKAGES = {
"BeautifulSoup",
"bs4",
"distribute",
"django-social-auth",
"nose",
"pep8",
"pycrypto",
"pypular",
"sklearn",
}
SESSION = requests.Session()
def get_json_url(package_name):
return BASE_URL + "/" + package_name + "/json"
def annotate_wheels(packages):
print("Getting wheel data...")
num_packages = len(packages)
for index, package in enumerate(packages):
print(index + 1, num_packages, package["name"])
has_wheel = False
url = get_json_url(package["name"])
response = SESSION.get(url)
if response.status_code != 200:
print(" ! Skipping " + package["name"])
continue
data = response.json()
for download in data["urls"]:
if download["packagetype"] == "bdist_wheel":
has_wheel = True
package["wheel"] = has_wheel
# Display logic. I know, I'm sorry.
package["value"] = 1
if has_wheel:
package["css_class"] = "success"
package["icon"] = "\u2713" # Check mark
package["title"] = "This package provides a wheel."
else:
package["css_class"] = "default"
package["icon"] = "\u2717" # Ballot X
package["title"] = "This package has no wheel archives uploaded " "(yet!)."
def get_top_packages():
print("Getting packages...")
with open("top-pypi-packages.json") as data_file:
packages = json.load(data_file)["rows"]
# Rename keys
for package in packages:
package["downloads"] = package.pop("download_count")
package["name"] = package.pop("project")
return packages
def not_deprecated(package):
return package["name"] not in DEPRECATED_PACKAGES
def remove_irrelevant_packages(packages, limit):
print("Removing cruft...")
active_packages = list(filter(not_deprecated, packages))
return active_packages[:limit]
def save_to_file(packages, file_name):
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
with open(file_name, "w") as f:
f.write(
json.dumps(
{
"data": packages,
"last_update": now.strftime("%A, %d %B %Y, %X %Z"),
},
indent=1,
)
)