-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_package_popularity.py
49 lines (41 loc) · 1.34 KB
/
get_package_popularity.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
import re
import urllib.request
# sorted_by possible value:
# 'by_inst'
# 'by_vote'
def get_package_popularity(field):
url = "https://popcon.debian.org/"
popularity = dict()
data = urllib.request.urlopen(url + 'by_' + field)
for line in data:
linestr = line.decode('utf-8')
# Ignore comments
if linestr.startswith('#'):
continue
if linestr.startswith('-'):
continue
results = linestr.strip().split(None,7)
if len(results) < 4:
continue
package_name = results[1]
if re.search(r'[^A-Za-z0-_\+\-\.]', package_name):
continue
if package_name not in popularity:
values = dict()
values['rank'] = int(results[0])
values['inst'] = int(results[2])
values['vote'] = int(results[3])
values['maintainer'] = results[7]
popularity[package_name] = values
else:
print('package_name duplicated?')
exit()
packages = []
for (package_name, values) in popularity.items():
values['package_name'] = package_name
packages.append(values)
return packages
if __name__ == "__main__":
field = 'inst'
for pkg in get_package_popularity(field):
print(f'{pkg['rank']}: {pkg['package_name']} ({pkg[field]})')