diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/syndication/medium.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/syndication/medium.py b/app/syndication/medium.py index f3164ec..9787a1a 100644 --- a/app/syndication/medium.py +++ b/app/syndication/medium.py @@ -1,14 +1,23 @@ from django.conf import settings +from bs4 import BeautifulSoup from medium import Client +def absolute_urls_for_syndication(s): + soup = BeautifulSoup(s, "lxml") + for a in soup.find_all('a'): + if a['href'][:1] == "/": + a['href'] = "https://luxagraf.net%s" % a['href'] + print(soup) + + def post_to_medium(item): client = Client(application_id=settings.MEDIUM_CLIENT_ID, application_secret=settings.MEDIUM_CLIENT_SECRET) client.access_token = settings.MEDIUM_INT_TOKEN user = client.get_current_user() head = '<p><i>This was originally posted <a href="https://luxagraf.net%s" rel="canonical">on my own site</a>.</i></p>' % item.content_object.get_absolute_url() - body = "%s %s" % (head, item.content_object.body_html) + body = "%s %s" % (head, absolute_urls_for_syndication(item.content_object.body_html)) # Create a post. post = client.create_post( user_id=user["id"], |