-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_top_100_nuget.py
More file actions
29 lines (23 loc) · 869 Bytes
/
Copy pathget_top_100_nuget.py
File metadata and controls
29 lines (23 loc) · 869 Bytes
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
#James Otten 2016
import requests
from pyquery import PyQuery as pq
import os
from time import gmtime, strftime
package_dir = 'packages' + strftime("%Y-%m-%d_%H:%M:%S", gmtime())
os.mkdir(package_dir)
packages = []
d = pq(url='https://www.nuget.org/stats/packages')
for a in d('.statistics-rank + td > a'):
packages.append(str(a.text))
for package in packages:
package_page = 'https://www.nuget.org/packages/%s' % package
print(package_page)
d = pq(url=package_page)
download_url = d('a[title="Download the raw nupkg file."]').attr('href')
print(download_url)
file_name = '%s/%s.nupkg' % (package_dir, '.'.join(download_url.split('/')[-2:]))
print(file_name)
with open(file_name, 'wb') as handle:
res = requests.get(download_url, stream=True)
for block in res.iter_content(1024):
handle.write(block)