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
+ # ///
1
10
import requests
2
11
from rich import print
3
12
from bs4 import BeautifulSoup
4
13
import sys
14
+ from rich .table import Table
5
15
6
16
7
17
def get_packages (url ):
@@ -13,6 +23,10 @@ def get_packages(url):
13
23
print (f"Failed to retrieve the webpage. Status code: { response .status_code } " )
14
24
exit (1 )
15
25
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
+
16
30
# Parse the HTML content
17
31
soup = BeautifulSoup (response .content , "html.parser" )
18
32
@@ -28,15 +42,13 @@ def get_packages(url):
28
42
return h3_tags
29
43
30
44
31
- # Print the sorted list
32
-
33
-
34
45
def get_tidelift_data (packages ):
35
-
36
46
packages_data = [{"platform" : "pypi" , "name" : h3 } for h3 in packages ]
37
47
38
48
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
+ )
40
52
41
53
res .raise_for_status ()
42
54
@@ -55,10 +67,7 @@ def get_tidelift_data(packages):
55
67
if package not in package_names :
56
68
package_data .append ((package , None , None ))
57
69
58
-
59
70
# Print the collected data in aligned columns
60
- from rich .columns import Columns
61
- from rich .table import Table
62
71
63
72
# Create a table for aligned output
64
73
table = Table (show_header = True , header_style = "bold magenta" )
@@ -85,6 +94,7 @@ def maybefloat(x):
85
94
86
95
print (table )
87
96
97
+
88
98
if __name__ == "__main__" :
89
99
# URL of the webpage
90
100
if sys .argv [1 ] == "--org" :
@@ -99,4 +109,4 @@ def maybefloat(x):
99
109
print ("Invalid argument. Please use either --org ORG or --user USER" )
100
110
exit (1 )
101
111
102
- get_tidelift_data (packages )
112
+ get_tidelift_data (packages )
0 commit comments