mirror of
https://github.com/craigerl/aprsd.git
synced 2025-08-02 13:42:26 -04:00
fixed list-plugins
This patch fixes the list-plugins and list-extensions. Pypi changed their search page to require javascript, which breaks python scripts....
This commit is contained in:
parent
b1a830d54e
commit
ec1adf4182
@ -13,9 +13,9 @@ from oslo_config import cfg
|
|||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import (
|
from aprsd import ( # noqa: F401
|
||||||
cli_helper,
|
cli_helper,
|
||||||
conf, # noqa
|
conf,
|
||||||
)
|
)
|
||||||
|
|
||||||
# local imports here
|
# local imports here
|
||||||
|
@ -4,10 +4,8 @@ import inspect
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
from traceback import print_tb
|
from traceback import print_tb
|
||||||
from urllib.parse import urljoin
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
@ -162,13 +160,15 @@ def show_built_in_plugins(console):
|
|||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
|
|
||||||
def _get_pypi_packages():
|
def _get_pypi_packages_OLD():
|
||||||
query = "aprsd"
|
query = "aprsd"
|
||||||
snippets = []
|
snippets = []
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
|
c = Console()
|
||||||
for page in range(1, 3):
|
for page in range(1, 3):
|
||||||
params = {"q": query, "page": page}
|
params = {"q": query, "page": page}
|
||||||
r = s.get(PYPI_URL, params=params)
|
r = s.get(PYPI_URL, params=params)
|
||||||
|
c.print(f"r = {r.text}")
|
||||||
soup = BeautifulSoup(r.text, "html.parser")
|
soup = BeautifulSoup(r.text, "html.parser")
|
||||||
snippets += soup.select('a[class*="snippet"]')
|
snippets += soup.select('a[class*="snippet"]')
|
||||||
if not hasattr(s, "start_url"):
|
if not hasattr(s, "start_url"):
|
||||||
@ -177,8 +177,34 @@ def _get_pypi_packages():
|
|||||||
return snippets
|
return snippets
|
||||||
|
|
||||||
|
|
||||||
|
def _get_pypi_packages():
|
||||||
|
if simple_r := requests.get(
|
||||||
|
"https://pypi.org/simple",
|
||||||
|
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
|
||||||
|
):
|
||||||
|
simple_response = simple_r.json()
|
||||||
|
else:
|
||||||
|
simple_response = {}
|
||||||
|
|
||||||
|
key = "aprsd"
|
||||||
|
matches = [
|
||||||
|
p["name"] for p in simple_response["projects"] if p["name"].startswith(key)
|
||||||
|
]
|
||||||
|
|
||||||
|
packages = []
|
||||||
|
for pkg in matches:
|
||||||
|
# Get info for first match
|
||||||
|
if r := requests.get(
|
||||||
|
f"https://pypi.org/pypi/{pkg}/json",
|
||||||
|
headers={"Accept": "application/json"},
|
||||||
|
):
|
||||||
|
packages.append(r.json())
|
||||||
|
|
||||||
|
return packages
|
||||||
|
|
||||||
|
|
||||||
def show_pypi_plugins(installed_plugins, console):
|
def show_pypi_plugins(installed_plugins, console):
|
||||||
snippets = _get_pypi_packages()
|
packages = _get_pypi_packages()
|
||||||
|
|
||||||
title = Text.assemble(
|
title = Text.assemble(
|
||||||
("Pypi.org APRSD Installable Plugin Packages\n\n", "bold magenta"),
|
("Pypi.org APRSD Installable Plugin Packages\n\n", "bold magenta"),
|
||||||
@ -193,33 +219,21 @@ def show_pypi_plugins(installed_plugins, console):
|
|||||||
table.add_column("Version", style="yellow", justify="center")
|
table.add_column("Version", style="yellow", justify="center")
|
||||||
table.add_column("Released", style="bold green", justify="center")
|
table.add_column("Released", style="bold green", justify="center")
|
||||||
table.add_column("Installed?", style="red", justify="center")
|
table.add_column("Installed?", style="red", justify="center")
|
||||||
for snippet in snippets:
|
|
||||||
link = urljoin(PYPI_URL, snippet.get("href"))
|
|
||||||
package = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('span[class*="name"]').text.strip()
|
|
||||||
)
|
|
||||||
version = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('span[class*="version"]').text.strip()
|
|
||||||
)
|
|
||||||
created = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('span[class*="created"]').text.strip()
|
|
||||||
)
|
|
||||||
description = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('p[class*="description"]').text.strip()
|
|
||||||
)
|
|
||||||
emoji = ":open_file_folder:"
|
emoji = ":open_file_folder:"
|
||||||
|
for package in packages:
|
||||||
|
link = package["info"]["package_url"]
|
||||||
|
version = package["info"]["version"]
|
||||||
|
package_name = package["info"]["name"]
|
||||||
|
description = package["info"]["summary"]
|
||||||
|
created = package["releases"][version][0]["upload_time"]
|
||||||
|
|
||||||
if "aprsd-" not in package or "-plugin" not in package:
|
if "aprsd-" not in package_name or "-plugin" not in package_name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
under = package.replace("-", "_")
|
under = package_name.replace("-", "_")
|
||||||
if under in installed_plugins:
|
installed = "Yes" if under in installed_plugins else "No"
|
||||||
installed = "Yes"
|
|
||||||
else:
|
|
||||||
installed = "No"
|
|
||||||
|
|
||||||
table.add_row(
|
table.add_row(
|
||||||
f"[link={link}]{emoji}[/link] {package}",
|
f"[link={link}]{emoji}[/link] {package_name}",
|
||||||
description,
|
description,
|
||||||
version,
|
version,
|
||||||
created,
|
created,
|
||||||
@ -231,7 +245,7 @@ def show_pypi_plugins(installed_plugins, console):
|
|||||||
|
|
||||||
|
|
||||||
def show_pypi_extensions(installed_extensions, console):
|
def show_pypi_extensions(installed_extensions, console):
|
||||||
snippets = _get_pypi_packages()
|
packages = _get_pypi_packages()
|
||||||
|
|
||||||
title = Text.assemble(
|
title = Text.assemble(
|
||||||
("Pypi.org APRSD Installable Extension Packages\n\n", "bold magenta"),
|
("Pypi.org APRSD Installable Extension Packages\n\n", "bold magenta"),
|
||||||
@ -245,33 +259,21 @@ def show_pypi_extensions(installed_extensions, console):
|
|||||||
table.add_column("Version", style="yellow", justify="center")
|
table.add_column("Version", style="yellow", justify="center")
|
||||||
table.add_column("Released", style="bold green", justify="center")
|
table.add_column("Released", style="bold green", justify="center")
|
||||||
table.add_column("Installed?", style="red", justify="center")
|
table.add_column("Installed?", style="red", justify="center")
|
||||||
for snippet in snippets:
|
|
||||||
link = urljoin(PYPI_URL, snippet.get("href"))
|
|
||||||
package = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('span[class*="name"]').text.strip()
|
|
||||||
)
|
|
||||||
version = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('span[class*="version"]').text.strip()
|
|
||||||
)
|
|
||||||
created = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('span[class*="created"]').text.strip()
|
|
||||||
)
|
|
||||||
description = re.sub(
|
|
||||||
r"\s+", " ", snippet.select_one('p[class*="description"]').text.strip()
|
|
||||||
)
|
|
||||||
emoji = ":open_file_folder:"
|
emoji = ":open_file_folder:"
|
||||||
|
|
||||||
if "aprsd-" not in package or "-extension" not in package:
|
for package in packages:
|
||||||
|
link = package["info"]["package_url"]
|
||||||
|
version = package["info"]["version"]
|
||||||
|
package_name = package["info"]["name"]
|
||||||
|
description = package["info"]["summary"]
|
||||||
|
created = package["releases"][version][0]["upload_time"]
|
||||||
|
if "aprsd-" not in package_name or "-extension" not in package_name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
under = package.replace("-", "_")
|
under = package_name.replace("-", "_")
|
||||||
if under in installed_extensions:
|
installed = "Yes" if under in installed_extensions else "No"
|
||||||
installed = "Yes"
|
|
||||||
else:
|
|
||||||
installed = "No"
|
|
||||||
|
|
||||||
table.add_row(
|
table.add_row(
|
||||||
f"[link={link}]{emoji}[/link] {package}",
|
f"[link={link}]{emoji}[/link] {package_name}",
|
||||||
description,
|
description,
|
||||||
version,
|
version,
|
||||||
created,
|
created,
|
||||||
@ -337,5 +339,7 @@ def list_extensions(ctx):
|
|||||||
|
|
||||||
with console.status("Show APRSD Extensions") as status:
|
with console.status("Show APRSD Extensions") as status:
|
||||||
status.update("Fetching pypi.org APRSD Extensions")
|
status.update("Fetching pypi.org APRSD Extensions")
|
||||||
|
|
||||||
|
status.update("Looking for installed APRSD Extensions")
|
||||||
installed_extensions = get_installed_extensions()
|
installed_extensions = get_installed_extensions()
|
||||||
show_pypi_extensions(installed_extensions, console)
|
show_pypi_extensions(installed_extensions, console)
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
aprslib>=0.7.0
|
aprslib>=0.7.0
|
||||||
# For the list-plugins pypi.org search scraping
|
|
||||||
beautifulsoup4
|
|
||||||
click
|
click
|
||||||
dataclasses-json
|
dataclasses-json
|
||||||
haversine
|
haversine
|
||||||
|
@ -9,8 +9,6 @@ attrs==24.3.0
|
|||||||
# rush
|
# rush
|
||||||
ax253==0.1.5.post1
|
ax253==0.1.5.post1
|
||||||
# via kiss3
|
# via kiss3
|
||||||
beautifulsoup4==4.12.3
|
|
||||||
# via -r requirements.in
|
|
||||||
bitarray==3.0.0
|
bitarray==3.0.0
|
||||||
# via
|
# via
|
||||||
# ax253
|
# ax253
|
||||||
@ -39,7 +37,7 @@ kiss3==8.0.0
|
|||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
loguru==0.7.3
|
loguru==0.7.3
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
marshmallow==3.23.2
|
marshmallow==3.23.3
|
||||||
# via dataclasses-json
|
# via dataclasses-json
|
||||||
mypy-extensions==1.0.0
|
mypy-extensions==1.0.0
|
||||||
# via typing-inspect
|
# via typing-inspect
|
||||||
@ -78,8 +76,6 @@ rich==12.6.0
|
|||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
rush==2021.4.0
|
rush==2021.4.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
soupsieve==2.6
|
|
||||||
# via beautifulsoup4
|
|
||||||
stevedore==5.4.0
|
stevedore==5.4.0
|
||||||
# via oslo-config
|
# via oslo-config
|
||||||
thesmuggler==1.0.1
|
thesmuggler==1.0.1
|
||||||
|
@ -2,9 +2,9 @@ from unittest import mock
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import (
|
from aprsd import ( # noqa: F401
|
||||||
client,
|
client,
|
||||||
conf, # noqa: F401
|
conf,
|
||||||
packets,
|
packets,
|
||||||
)
|
)
|
||||||
from aprsd.plugins import notify as notify_plugin
|
from aprsd.plugins import notify as notify_plugin
|
||||||
|
@ -3,8 +3,8 @@ from unittest import mock
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import (
|
from aprsd import ( # noqa: F401
|
||||||
conf, # noqa: F401
|
conf,
|
||||||
packets,
|
packets,
|
||||||
plugins,
|
plugins,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user