fix extracting content

This commit is contained in:
Silver Ghost 2022-10-25 11:46:04 +03:00
parent 88143da955
commit a78f7e72ed
No known key found for this signature in database

View File

@ -8,7 +8,7 @@ from django.conf import settings
class URL(APIView): class URL(APIView):
def get_title(self, url): def get_title(self, url: str):
try: try:
response = requests.get(url) response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser') soup = BeautifulSoup(response.text, 'html.parser')
@ -17,6 +17,15 @@ class URL(APIView):
except AttributeError: except AttributeError:
return None return None
def get_content(self, url: str):
url = settings.READABILITY_HOST.rstrip(
'/') + '/api/content/v1/parser?url=' + url
try:
response = requests.get(url).json()
return response['excerpt']
except AttributeError:
return None
def post(self, request, format=None): def post(self, request, format=None):
url = request.GET.get('url') url = request.GET.get('url')
if url: if url: