Last active
January 17, 2020 08:38
-
-
Save uoxiu/0a07037b03c5e93d783c2fb5549c9702 to your computer and use it in GitHub Desktop.
Get list of pypi package versions on specific date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import subprocess | |
import requests | |
from dateutil import parser | |
from_date = datetime.datetime(year=2019, month=4, day=24) | |
a = subprocess.check_output(['pip', 'freeze']).decode('utf-8') | |
for line in a.split('\n'): | |
if not line: | |
continue | |
pack, version = line.split('==') | |
response = requests.get(f'https://pypi.org/pypi/{pack}/json') | |
if response.status_code == 200: | |
data = response.json() | |
dates = {} | |
for package_version, candidates in data.get('releases').items(): | |
for candidate in candidates: | |
date = parser.parse(candidate['upload_time']) | |
dates[package_version] = date | |
for date in list(reversed(sorted(filter(lambda d: d < from_date, dates.values())))): | |
found_version = list(dates.keys())[list(dates.values()).index(date)] | |
print(pack + '==' + found_version) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment