Spaces:
Sleeping
Sleeping
import requests | |
from bs4 import BeautifulSoup | |
import re | |
import gradio as gr | |
def get_blocked_urls(): | |
""" | |
Get a list of blocked URLs. | |
Returns: | |
list: A list of blocked URLs. | |
Raises: | |
None. | |
""" | |
url = 'https://colab.research.google.com/' | |
r = requests.get(url) | |
if r.status_code == 200: | |
result = [] | |
soup = BeautifulSoup(r.text, 'html.parser') | |
# search for script that contains "external_polymer_binary" in attr | |
for script in soup.find_all('script'): | |
if "external_polymer_binary" in str(script): | |
r_js = requests.get(script['src']) | |
# print(r_js.text) | |
pattern = r"'(.*?)webui(.*?)'" | |
match = re.search(pattern, r_js.text) | |
raw_string = match.group(0) | |
# trim 1 char front and back, split the text with ';' into array | |
raw_string = raw_string[1:-1].split(';') | |
result = raw_string | |
if len(result) > 0: | |
return (result) | |
else: | |
return (["failed :<"]) | |
else: | |
return (["res code: "+r.status_code]) | |
def handle_refresh(): | |
""" | |
Generates an HTML ordered list of blocked URLs. | |
Returns: | |
str: The HTML string containing the ordered list of blocked URLs. | |
""" | |
xs = "<ol>" | |
for url in get_blocked_urls(): | |
xs += "<li><code>"+url+"</code></li>" | |
xs += "</ol>" | |
return xs | |
with gr.Blocks( | |
analytics_enabled=False, title="GGL Checks", theme="NoCrypt/miku" | |
) as demo: | |
gr.HTML("""<center><h1>GGL Checks</h1></center>""") | |
refresh = gr.Button("Refresh", variant="primary") | |
html = gr.HTML() | |
refresh.click(handle_refresh, outputs=[html]) | |
demo.launch(debug=True) |