Skip to content

Instantly share code, notes, and snippets.

@capjamesg
Last active October 6, 2022 20:12
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/ac5ce5b0743819f7a0d80c151d62555e to your computer and use it in GitHub Desktop.
Save capjamesg/ac5ce5b0743819f7a0d80c151d62555e to your computer and use it in GitHub Desktop.
# Code to advance discussion around url_summary implementation
# Still in development
from urllib.parse import urlparse
url = "https://github.com/capjamesg/indieweb-utils/pulls/1"
callbacks = {
"github.com": [
lambda path: "A comment on pull request " + path[1] if len(path) > 2 and path[2] == "pulls" else "",
lambda path: "A comment on GitHub project " + path[1] if len(path) > 1 else ""
]
}
parsed_url = urlparse(url)
domain = parsed_url.netloc
path = parsed_url.path.split("/")
path.remove("")
functions = callbacks[domain]
for f in functions:
if f(path) != "":
print(f(path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment