Реализовано продвижение в одноклассниках #10
This commit is contained in:
parent
a192d7e2d0
commit
2c1cdec1c2
30
cms/views.py
30
cms/views.py
@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from json import JSONDecoder
|
from json import JSONDecoder, JSONEncoder
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
@ -42,10 +42,38 @@ class ArticleView(View):
|
|||||||
message=article.body,
|
message=article.body,
|
||||||
attachments=article.link)
|
attachments=article.link)
|
||||||
|
|
||||||
|
def _promote_to_ok(self, article: Article):
|
||||||
|
import ok_api
|
||||||
|
|
||||||
|
ok_access_token = os.getenv('OK_ACCESS_TOKEN')
|
||||||
|
ok_application_key = os.getenv('OK_APPLICATION_KEY')
|
||||||
|
ok_application_secret_key = os.getenv('OK_APPLICATION_SECRET_KEY')
|
||||||
|
|
||||||
|
session = ok_api.OkApi(access_token=ok_access_token,
|
||||||
|
application_key=ok_application_key,
|
||||||
|
application_secret_key=ok_application_secret_key)
|
||||||
|
attachments = {
|
||||||
|
'media': [
|
||||||
|
{
|
||||||
|
'type': 'text',
|
||||||
|
'text': article.body,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'link',
|
||||||
|
'url': article.link,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
encoded_attachments = JSONEncoder().encode(attachments)
|
||||||
|
session.mediatopic.post(type='GROUP_THEME',
|
||||||
|
gid='70000001426867',
|
||||||
|
attachment=encoded_attachments)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
article_data = JSONDecoder().decode(request.body.decode())
|
article_data = JSONDecoder().decode(request.body.decode())
|
||||||
article = Article.objects.create(**article_data)
|
article = Article.objects.create(**article_data)
|
||||||
self._promote_to_telegram(article)
|
self._promote_to_telegram(article)
|
||||||
|
self._promote_to_ok(article)
|
||||||
self._promote_to_vk(article)
|
self._promote_to_vk(article)
|
||||||
response = {'ok': True}
|
response = {'ok': True}
|
||||||
return JsonResponse(response)
|
return JsonResponse(response)
|
||||||
|
@ -4,6 +4,7 @@ charset-normalizer==2.1.1
|
|||||||
Django==4.1.4
|
Django==4.1.4
|
||||||
django-dotenv==1.4.2
|
django-dotenv==1.4.2
|
||||||
idna==3.4
|
idna==3.4
|
||||||
|
ok-api==1.0.1
|
||||||
requests==2.28.1
|
requests==2.28.1
|
||||||
sqlparse==0.4.3
|
sqlparse==0.4.3
|
||||||
urllib3==1.26.13
|
urllib3==1.26.13
|
||||||
|
Loading…
x
Reference in New Issue
Block a user