Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from bs4 import BeautifulSoup
|
3 |
+
import re
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def get_blocked_urls():
|
7 |
+
"""
|
8 |
+
Get a list of blocked URLs.
|
9 |
+
|
10 |
+
Returns:
|
11 |
+
list: A list of blocked URLs.
|
12 |
+
|
13 |
+
Raises:
|
14 |
+
None.
|
15 |
+
"""
|
16 |
+
url = 'https://colab.research.google.com/'
|
17 |
+
r = requests.get(url)
|
18 |
+
if r.status_code == 200:
|
19 |
+
result = []
|
20 |
+
soup = BeautifulSoup(r.text, 'html.parser')
|
21 |
+
# search for script that contains "external_polymer_binary" in attr
|
22 |
+
for script in soup.find_all('script'):
|
23 |
+
if "external_polymer_binary" in str(script):
|
24 |
+
|
25 |
+
r_js = requests.get(script['src'])
|
26 |
+
# print(r_js.text)
|
27 |
+
|
28 |
+
pattern = r"'(.*?)webui(.*?)'"
|
29 |
+
match = re.search(pattern, r_js.text)
|
30 |
+
raw_string = match.group(0)
|
31 |
+
|
32 |
+
# trim 1 char front and back, split the text with ';' into array
|
33 |
+
raw_string = raw_string[1:-1].split(';')
|
34 |
+
result = raw_string
|
35 |
+
|
36 |
+
if len(result) > 0:
|
37 |
+
return (result)
|
38 |
+
else:
|
39 |
+
return (["failed :<"])
|
40 |
+
|
41 |
+
else:
|
42 |
+
return (["res code: "+r.status_code])
|
43 |
+
|
44 |
+
|
45 |
+
def handle_refresh():
|
46 |
+
"""
|
47 |
+
Generates an HTML ordered list of blocked URLs.
|
48 |
+
|
49 |
+
Returns:
|
50 |
+
str: The HTML string containing the ordered list of blocked URLs.
|
51 |
+
"""
|
52 |
+
xs = "<ol>"
|
53 |
+
for url in get_blocked_urls():
|
54 |
+
xs += "<li><code>"+url+"</code></li>"
|
55 |
+
xs += "</ol>"
|
56 |
+
return xs
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
with gr.Blocks(
|
61 |
+
analytics_enabled=False, title="GGL Checks", theme="NoCrypt/miku"
|
62 |
+
) as demo:
|
63 |
+
gr.HTML("""<center><h1>GGL Checks</h1></center>""")
|
64 |
+
refresh = gr.Button("Refresh", variant="primary")
|
65 |
+
html = gr.HTML()
|
66 |
+
refresh.click(handle_refresh, outputs=[html])
|
67 |
+
|
68 |
+
|
69 |
+
demo.launch(debug=True)
|