Реализовано продвижение в одноклассниках #10
This commit is contained in:
parent
a192d7e2d0
commit
2c1cdec1c2
30
cms/views.py
30
cms/views.py
@ -1,5 +1,5 @@
|
||||
import os
|
||||
from json import JSONDecoder
|
||||
from json import JSONDecoder, JSONEncoder
|
||||
|
||||
import requests
|
||||
from django.http import JsonResponse
|
||||
@ -42,10 +42,38 @@ class ArticleView(View):
|
||||
message=article.body,
|
||||
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):
|
||||
article_data = JSONDecoder().decode(request.body.decode())
|
||||
article = Article.objects.create(**article_data)
|
||||
self._promote_to_telegram(article)
|
||||
self._promote_to_ok(article)
|
||||
self._promote_to_vk(article)
|
||||
response = {'ok': True}
|
||||
return JsonResponse(response)
|
||||
|
@ -4,6 +4,7 @@ charset-normalizer==2.1.1
|
||||
Django==4.1.4
|
||||
django-dotenv==1.4.2
|
||||
idna==3.4
|
||||
ok-api==1.0.1
|
||||
requests==2.28.1
|
||||
sqlparse==0.4.3
|
||||
urllib3==1.26.13
|
||||
|
Loading…
x
Reference in New Issue
Block a user