From 78b2f8220d0c4bc85069492e157a70147d12e031 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 6 Nov 2017 21:08:02 +1100 Subject: [PATCH] Add simple support for sending Webmentions using the ronkyuu library --- Pipfile | 1 + Pipfile.lock | 9 ++++++++- entries/jobs.py | 8 ++++++++ micropub/views.py | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Pipfile b/Pipfile index 368e0e8..1b512ef 100644 --- a/Pipfile +++ b/Pipfile @@ -40,6 +40,7 @@ django-analytical = "*" django-model-utils = "*" python-jose = "*" django-rq = "*" +ronkyuu = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 475adca..955b4f9 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "47ed3b4022e12ce5fcdf671cdc9e8512a30c925745dd07a2385d951c3f1a4315" + "sha256": "028ac3e8ca1afd917bb4d7d3e0b93c5a8b52a2700cb4e67e2e72ffae8594dfab" }, "host-environment-markers": { "implementation_name": "cpython", @@ -470,6 +470,13 @@ ], "version": "==1.0.12" }, + "ronkyuu": { + "hashes": [ + "sha256:5aa77b39d301bc174ab99ba8a53954627771cb501651a12103c58f51b32e84bf", + "sha256:85b25fef7f5fb0c93afd5377ea35b5ff72b2458f926bafdf10f0c9a1e19cab10" + ], + "version": "==0.6" + }, "rq": { "hashes": [ "sha256:aa9e73113713e3b2e8d633ebb5f8ceccf5c8c97c1aae4356dc3f46d446129f71", diff --git a/entries/jobs.py b/entries/jobs.py index b5004ae..49968c7 100644 --- a/entries/jobs.py +++ b/entries/jobs.py @@ -1,9 +1,17 @@ import requests from django.conf import settings from django_rq import job +from ronkyuu import webmention @job def ping_hub(*urls): data = [('hub.mode', 'publish')] + [('hub.url[]', url) for url in urls] requests.post(settings.PUSH_HUB, data=data) + + +@job +def send_mentions(url): + result = webmention.findMentions(url) + for target in result['refs']: + webmention.sendWebmention(url, target) diff --git a/micropub/views.py b/micropub/views.py index 868e003..3c21209 100644 --- a/micropub/views.py +++ b/micropub/views.py @@ -5,7 +5,7 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from urllib.parse import urljoin -from entries.jobs import ping_hub +from entries.jobs import ping_hub, send_mentions from entries.models import Entry from entries.kinds import Article, Note from lemoncurry import utils @@ -44,6 +44,7 @@ def micropub(request): reverse('entries:rss'), )) ping_hub.delay(perma, *others) + send_mentions.delay(perma) res = HttpResponse(status=201) res['Location'] = perma