Add simple support for sending Webmentions using the ronkyuu library
This commit is contained in:
parent
3cc2fe798f
commit
78b2f8220d
4 changed files with 19 additions and 2 deletions
1
Pipfile
1
Pipfile
|
@ -40,6 +40,7 @@ django-analytical = "*"
|
|||
django-model-utils = "*"
|
||||
python-jose = "*"
|
||||
django-rq = "*"
|
||||
ronkyuu = "*"
|
||||
|
||||
|
||||
[dev-packages]
|
||||
|
|
9
Pipfile.lock
generated
9
Pipfile.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue