1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/project/blog/utils.py

22 lines
464 B
Python
Raw Normal View History

2016-02-20 19:27:18 +00:00
import requests
from django.conf import settings
API_PATH = "https://public-api.wordpress.com/rest/v1.1/sites/{0}/posts/slug:{1}"
2016-02-20 21:37:03 +00:00
def build_url(slug):
if not slug:
return
return API_PATH.format(settings.WORDPRESS_URL, slug)
2016-02-20 19:27:18 +00:00
def get_post(slug):
if not slug:
return
2016-02-20 21:37:03 +00:00
response = requests.get(build_url(slug))
2016-02-20 19:27:18 +00:00
if response.status_code != 200:
return
data = response.json()
return data if "ID" in data else False