blob: 2e11c7dbaf529e759df3fe3311df900fd83dd450 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
from django.conf import settings
from django.test.client import Client
from bs4 import BeautifulSoup
from medium import Client as MediumClient
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']
return soup
def post_to_medium(item):
client = MediumClient(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.get_absolute_url()
body = "%s %s" % (head, absolute_urls_for_syndication(item.body_html))
# Create a post.
post = client.create_post(
user_id=user["id"],
title=item.title,
content=body,
content_format="html",
publish_status="public",
canonical_url="https://luxagraf.net%s" % item.get_absolute_url(),
license="all-rights-reserved"
)
return post["url"]
def build_facebook_feed():
print("+++++++++++++building+++++++++++")
c = Client()
response = c.get('/iafeed.xml', HTTP_HOST='127.0.0.1')
f = open("%siafeed.xml" % settings.FLATFILES_ROOT, 'wb')
f.write(response.content)
f.close()
|