From 583afa3c67df13d4845ef07a70a159688052584c Mon Sep 17 00:00:00 2001 From: luxagraf <sng@luxagraf.net> Date: Tue, 29 Mar 2016 21:29:15 -0400 Subject: added a syndication model and way to publish to medium --- app/syndication/medium.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/syndication/medium.py (limited to 'app/syndication/medium.py') diff --git a/app/syndication/medium.py b/app/syndication/medium.py new file mode 100644 index 0000000..b7a1c6d --- /dev/null +++ b/app/syndication/medium.py @@ -0,0 +1,22 @@ +from django.conf import settings + +from medium import Client + + +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="%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) + # Create a post. + post = client.create_post( + user_id=user["id"], + title=item.content_object.title, + content=body, + content_format="html", + publish_status="draft" + ) + item.rel_link = post["url"] + item.status = 2 + item.save() -- cgit v1.2.3-70-g09d2