Add simple support for sending Webmentions using the ronkyuu library

This commit is contained in:
Danielle McLean 2017-11-06 21:08:02 +11:00
parent 3cc2fe798f
commit 78b2f8220d
Signed by untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
4 changed files with 19 additions and 2 deletions

View file

@ -40,6 +40,7 @@ django-analytical = "*"
django-model-utils = "*" django-model-utils = "*"
python-jose = "*" python-jose = "*"
django-rq = "*" django-rq = "*"
ronkyuu = "*"
[dev-packages] [dev-packages]

9
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "47ed3b4022e12ce5fcdf671cdc9e8512a30c925745dd07a2385d951c3f1a4315" "sha256": "028ac3e8ca1afd917bb4d7d3e0b93c5a8b52a2700cb4e67e2e72ffae8594dfab"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
@ -470,6 +470,13 @@
], ],
"version": "==1.0.12" "version": "==1.0.12"
}, },
"ronkyuu": {
"hashes": [
"sha256:5aa77b39d301bc174ab99ba8a53954627771cb501651a12103c58f51b32e84bf",
"sha256:85b25fef7f5fb0c93afd5377ea35b5ff72b2458f926bafdf10f0c9a1e19cab10"
],
"version": "==0.6"
},
"rq": { "rq": {
"hashes": [ "hashes": [
"sha256:aa9e73113713e3b2e8d633ebb5f8ceccf5c8c97c1aae4356dc3f46d446129f71", "sha256:aa9e73113713e3b2e8d633ebb5f8ceccf5c8c97c1aae4356dc3f46d446129f71",

View file

@ -1,9 +1,17 @@
import requests import requests
from django.conf import settings from django.conf import settings
from django_rq import job from django_rq import job
from ronkyuu import webmention
@job @job
def ping_hub(*urls): def ping_hub(*urls):
data = [('hub.mode', 'publish')] + [('hub.url[]', url) for url in urls] data = [('hub.mode', 'publish')] + [('hub.url[]', url) for url in urls]
requests.post(settings.PUSH_HUB, data=data) 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)

View file

@ -5,7 +5,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from urllib.parse import urljoin 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.models import Entry
from entries.kinds import Article, Note from entries.kinds import Article, Note
from lemoncurry import utils from lemoncurry import utils
@ -44,6 +44,7 @@ def micropub(request):
reverse('entries:rss'), reverse('entries:rss'),
)) ))
ping_hub.delay(perma, *others) ping_hub.delay(perma, *others)
send_mentions.delay(perma)
res = HttpResponse(status=201) res = HttpResponse(status=201)
res['Location'] = perma res['Location'] = perma