Skip to content

Instantly share code, notes, and snippets.

@j2kun
Created October 30, 2024 22:10
Show Gist options
  • Save j2kun/a8f5c5a8d3d56b1f1bb98e948254a944 to your computer and use it in GitHub Desktop.
Save j2kun/a8f5c5a8d3d56b1f1bb98e948254a944 to your computer and use it in GitHub Desktop.
webmention utils
import indieweb_utils
def send_webmention(source_url, target_url, dry_run=False):
print(f"Found a webmention: {source_url} -> {target_url}")
try:
indieweb_utils.discover_webmention_endpoint(source_url)
except Exception as e:
print(f"Error discovering webmention endpoint: {e}")
return
if dry_run:
print("Dry run enabled, skipping webmention")
return
try:
response = indieweb_utils.send_webmention(source_url, target_url)
except indieweb_utils.webmentions.discovery.WebmentionEndpointNotFound:
print("Webmention endpoint not found.")
return
except Exception as e:
print(f"Webmention error: {e}")
return
print(response)
print("Webmention sent!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment