diff options
author | luxagraf <sng@luxagraf.net> | 2016-03-29 21:29:15 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2016-03-29 21:29:15 -0400 |
commit | 583afa3c67df13d4845ef07a70a159688052584c (patch) | |
tree | 58190d2dead223d23788c18f83715c20c1d62434 /app/syndication/medium.py | |
parent | c626861546bc3e33b068d929174a7d478c4f2bab (diff) |
added a syndication model and way to publish to medium
Diffstat (limited to 'app/syndication/medium.py')
-rw-r--r-- | app/syndication/medium.py | 22 |
1 files changed, 22 insertions, 0 deletions
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() |