adding fail check on JSON getblogposts
This commit is contained in:
@@ -7,6 +7,8 @@ import requests
|
|||||||
import datetime
|
import datetime
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
|
||||||
PY3K = sys.version_info >= (3,0)
|
PY3K = sys.version_info >= (3,0)
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
@@ -19,7 +21,10 @@ class Command(BaseCommand):
|
|||||||
response = requests.get(
|
response = requests.get(
|
||||||
'https://analytics.rowsandall.com/wp-json/wp/v2/posts?per_page=3')
|
'https://analytics.rowsandall.com/wp-json/wp/v2/posts?per_page=3')
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
blogs_json = response.json()
|
try:
|
||||||
|
blogs_json = response.json()
|
||||||
|
except JSONDecodeError:
|
||||||
|
blogs_json = []
|
||||||
else:
|
else:
|
||||||
blogs_json = []
|
blogs_json = []
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
@@ -46,4 +51,3 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS(
|
self.stdout.write(self.style.SUCCESS(
|
||||||
'Successfully processed blog posts'))
|
'Successfully processed blog posts'))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user