Last active
October 6, 2022 20:34
-
-
Save capjamesg/3547cde4df483078eacf343ef68028d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import urlparse | |
url = "https://github.com/capjamesg/indieweb-utils/pulls/1" | |
def _python_pull_request(path): | |
if len(path) > 2 or path[2] != "pulls": | |
return "A comment on a pull request in the " + path[1] + " GitHub repository." | |
def _python_generic_comment(path): | |
if len(path) >= 1: | |
return "A comment on GitHub project " + path[1] + "." | |
callbacks = { | |
"github.com": [ | |
_python_pull_request, | |
_python_generic_comment | |
] | |
} | |
def get_url_summary(url) -> str: | |
""" | |
Retrieve a URL summary for a provided URL. | |
:refs: https://indieweb.org/auto-url-summary | |
:param url: The URL to summarize. | |
:return: A summary of the URL. | |
:rtype: str | |
""" | |
parsed_url = urlparse(url) | |
domain = parsed_url.netloc | |
path = parsed_url.path.split("/") | |
path.remove("") | |
functions = callbacks[domain] | |
for f in functions: | |
summary = f(path) | |
if summary == None: | |
continue | |
return summary | |
print(get_url_summary(url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment