Skip to content

Instantly share code, notes, and snippets.

@capjamesg
Last active October 6, 2022 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capjamesg/3547cde4df483078eacf343ef68028d7 to your computer and use it in GitHub Desktop.
Save capjamesg/3547cde4df483078eacf343ef68028d7 to your computer and use it in GitHub Desktop.
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