Skip to content

Instantly share code, notes, and snippets.

@Jawschamp
Last active February 23, 2022 06:08
Show Gist options
  • Save Jawschamp/4a9ce987274a353c216a99e8be8ae2e7 to your computer and use it in GitHub Desktop.
Save Jawschamp/4a9ce987274a353c216a99e8be8ae2e7 to your computer and use it in GitHub Desktop.
Simple Python script that parses all file wheels (needs to be optimized)
import wheel_filename
import requests
from requests_html import HTMLSession
import re
from typing import NoReturn
class ParsePythonWheelFiles:
def __init__(self, wheel_file_name, module_name) -> NoReturn:
self.wheel_file_name = wheel_file_name
self.module_name = module_name
def parse_data(self):
# Make a method that strips all links from parse_pypi_wheel_distributions()
pwf = wheel_filename.parse_wheel_filename(self.wheel_file_name)
return pwf.platform_tags
def parse_wheel_distributions_filenames(self):
file_name_list = []
links = self.parse_pypi_wheel_distributions()
for link_files in links:
if link_files.endswith(".whl"):
file_name_list.append(link_files[107:])
return file_name_list
def parse_pypi_wheel_distributions(self):
get = HTMLSession().get(f"https://pypi.org/project/{self.module_name}/#files")
return get.html.absolute_links
def parse_wheel_platform_tags_urls(self, platform_tag: str, get_all_platforms_list: bool):
# the platform_tag parameter is used to get a list (array) of .whl files for your platform
for wheel_file_names in self.parse_wheel_distributions_filenames():
platform_tag_parser = self.parse_data() # Get platform info with a list
print(platform_tag_parser)
if get_all_platforms_list is True:
print("If you are trying to get a list of every available platform call"
'ParsePythonWheelFiles(self).parse_pypi_wheel_distributions()', "directly")
return exit()
else:
print("Error", exit())
class PythonWheelDownloader(ParsePythonWheelFiles):
def __init__(self) -> NoReturn:
super().__init__(self.wheel_file)
def download_wheel(url_list: list, platform: str) -> NoReturn:
for wheels in url_list:
print(wheels)
if re.search(wheels, platform):
print("Yes")
def test():
array = ['opencv_python-4.5.5.62-cp36-abi3-win32.whl', 'opencv_python-4.5.5.62-cp36-abi3-macosx_10_15_x86_64.whl', 'opencv_python-4.5.5.62-cp37-abi3-macosx_11_0_arm64.whl', 'opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl', 'opencv_python-4.5.5.62-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl']
for i in array:
parse = ParsePythonWheelFiles(wheel_file_name=i, module_name="opencv-python")
print(parse.parse_data())
test()
@Jawschamp
Copy link
Author

Jawschamp commented Feb 20, 2022

The next revision will have it's own Wheel Parser (ParsePythonWheelFiles.parse_wheel_platform_tags_urls(platform_tag, get_platforms). Currently trying to fix a very rare wheel filename error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment