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.

Revisions

  1. j2kun created this gist Oct 30, 2024.
    27 changes: 27 additions & 0 deletions util.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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!")