Source code for pyquickhelper.loghelper.pypi_helper

"""
Helpers to information for pypi version.


:githublink:`%|py|5`
"""
from datetime import datetime
import xmlrpc.client as xmlrpc_client


[docs]def enumerate_pypi_versions_date(name, url='https://pypi.python.org/pypi'): """ Retrieves version and releases dates for modules hosted on :epkg:`pypi`. :param name: module name :param url: url :return: list tuple (date, version, size) :githublink:`%|py|17` """ pypi = xmlrpc_client.ServerProxy(url) available = pypi.package_releases(name, True) for ver in available: res = pypi.release_urls(name, ver) for r in res: if isinstance(r['upload_time'], str): dt = datetime.strptime(r['upload_time'].split('.')[ 0], "%Y-%m-%dT%H:%M:%S") else: try: dt = datetime(* tuple(r['upload_time'].timetuple())[:6]) except AttributeError as e: raise AttributeError( "Unable to parse '{0}'".format(r['upload_time'])) from e yield dt, ver, r['size'] break