def find_last_version_pypi(package, delay): """Return the last version of a package """ url = 'https://pypi.org/project/{}/#history'.format(package) page = requests_get_handler(url) if page.status_code == 404: print('{} not found'.format(package)) return "" elements = pypi_parser(page.content) return elements[0][0]
def download_maven_jar(url, package, version, delay): """Download maven project jar. """ filename = get_name( package.split(':')[1], version, 'jar', package.split(':')[0] + '.') url = url + get_url(package, version, 'jar') r = requests_get_handler(url) if r.status_code == 404: # FIXME print('Error: ' + url + ' Not Found\n') with open(filename, 'wb') as f: f.write(r.content)
def find_version_timestamp_pypi(package, version, delay): """Return version timestamp using PyPI's website. """ url = 'https://pypi.org/project/{}/#history'.format(package) page = requests_get_handler(url) if page.status_code == 404: print('{} not found'.format(package)) return "" elements = pypi_parser(page.content) for versions in elements: if version == versions[0]: return versions[1] print('{} of {} not found'.format(version, package)) return ""
def find_last_version_maven(package, delay): """Return the last version of a package In case of error return empty string """ url = 'https://mvnrepository.com/artifact/' url = url + package.split(':')[0] + '/' + package.split(':')[1] page = requests_get_handler(url) if page.status_code == 404: return '' tree = html.fromstring(page.content) element = '//a[@class="vbtn release"]//text()' elements = tree.xpath(element) if len(elements) == 0: return "" return elements[0]
def get_version_timestamp_libio(pkg_mng, package, version): """Return version timestamp using libio. """ url = 'https://libraries.io/{}/{}/versions'.format(pkg_mng, package) for i in range(1, 100): page = requests_get_handler(url + '?page=' + str(i)) if page.status_code == 404: print('{} not found'.format(package)) return "" elements = libio_parser(page.content) for versions in elements: if version == versions[0]: return versions[1] if len(elements) == 0: break print('{} of {} not found'.format(version, package)) return ""
def get_pom_xml(url, project, version, delay): """Get the pom of a project. Args: url (str): URL to make the request project (str): Project name version (str): Project version delay (str): Second to sleep Returns: content (str): The contents of pom xml file. """ url = url + get_url(project, version, 'pom') r = requests_get_handler(url) if r.status_code == 404: # FIXME print('Error: ' + url + ' Not Found\n') return r.content
def find_last_version(url_v, package, delay): """Find the last release of a package. Args: url_v (str): Url to make the request. pakcage (str): Package name delay (int): Seconds to wait """ url = url_v + package.split(':')[0] + '/' + package.split(':')[1] page = requests_get_handler(url) if page.status_code == 404: return 'Error' tree = html.fromstring(page.content) element = '//a[@class="vbtn release"]//text()' elements = tree.xpath(element) if len(elements) == 0: return 'Not Found' return elements[0]
def find_version_timestamp_maven(package, version, delay): """Return version timestamp using mvnrepository.com. In case of error return empty string """ url = 'https://mvnrepository.com/artifact/{}/{}/{}'.format( package.split(':')[0], package.split(':')[1], version ) page = requests_get_handler(url) if page.status_code == 404: print('{} not found'.format(package)) return "" tree = html.fromstring(page.content) element = '//table[@class="grid"]//text()' elements = tree.xpath(element) for i, elem in enumerate(elements): if elem == 'Date': return elements[i+1].split('(')[1].split(')')[0] print('{} of {} not found'.format(version, package)) return ""