Skip to content

Commit 16f98cf

Browse files
committed
misc cleanup
1 parent 3841e0e commit 16f98cf

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tools/tide.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
# https://packaging.python.org/en/latest/specifications/inline-script-metadata/
2+
# /// script
3+
# requires-python = ">=3.12"
4+
# dependencies = [
5+
# "requests",
6+
# "rich",
7+
# "beautifulsoup4",
8+
# ]
9+
# ///
110
import requests
211
from rich import print
312
from bs4 import BeautifulSoup
413
import sys
14+
from rich.table import Table
515

616

717
def get_packages(url):
@@ -13,6 +23,10 @@ def get_packages(url):
1323
print(f"Failed to retrieve the webpage. Status code: {response.status_code}")
1424
exit(1)
1525

26+
if "A required part of this site couldn’t load" in response.text:
27+
print("Fastly is blocking us. Status code: 403")
28+
exit(1)
29+
1630
# Parse the HTML content
1731
soup = BeautifulSoup(response.content, "html.parser")
1832

@@ -28,15 +42,13 @@ def get_packages(url):
2842
return h3_tags
2943

3044

31-
# Print the sorted list
32-
33-
3445
def get_tidelift_data(packages):
35-
3646
packages_data = [{"platform": "pypi", "name": h3} for h3 in packages]
3747

3848
data = {"packages": packages_data}
39-
res = requests.post("https://tidelift.com/api/depci/estimate/bulk_estimates", json=data)
49+
res = requests.post(
50+
"https://tidelift.com/api/depci/estimate/bulk_estimates", json=data
51+
)
4052

4153
res.raise_for_status()
4254

@@ -55,10 +67,7 @@ def get_tidelift_data(packages):
5567
if package not in package_names:
5668
package_data.append((package, None, None))
5769

58-
5970
# Print the collected data in aligned columns
60-
from rich.columns import Columns
61-
from rich.table import Table
6271

6372
# Create a table for aligned output
6473
table = Table(show_header=True, header_style="bold magenta")
@@ -85,6 +94,7 @@ def maybefloat(x):
8594

8695
print(table)
8796

97+
8898
if __name__ == "__main__":
8999
# URL of the webpage
90100
if sys.argv[1] == "--org":
@@ -99,4 +109,4 @@ def maybefloat(x):
99109
print("Invalid argument. Please use either --org ORG or --user USER")
100110
exit(1)
101111

102-
get_tidelift_data(packages)
112+
get_tidelift_data(packages)

0 commit comments

Comments
 (0)