|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
import abc |
|
|
|
|
import os |
|
|
|
|
from urllib.parse import urlencode |
|
|
|
|
|
|
|
|
|
import requests |
|
|
|
|
|
|
|
|
|
from cms.models import Article |
|
|
|
|
from crossposting_backend.settings import promoter_secrets |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PromoteError(Exception): |
|
|
|
@ -21,13 +21,13 @@ class Promoter(abc.ABC):
|
|
|
|
|
|
|
|
|
|
class TelegramPromoter(Promoter): |
|
|
|
|
def promote(self): |
|
|
|
|
from crossposting_backend.settings import BOT_TOKEN, CHANNEL_ID |
|
|
|
|
|
|
|
|
|
long_text = f'{self.article.body}\n{self.article.link}' |
|
|
|
|
querystring = (('chat_id', CHANNEL_ID), ('text', long_text)) |
|
|
|
|
channel_id = promoter_secrets['TELEGRAM_CHAT_ID'] |
|
|
|
|
bot_token = promoter_secrets['TELEGRAM_BOT_TOKEN'] |
|
|
|
|
querystring = (('chat_id', channel_id), ('text', long_text)) |
|
|
|
|
encoded_querystring = urlencode(querystring) |
|
|
|
|
|
|
|
|
|
send_message_url = f'https://api.telegram.org/bot{BOT_TOKEN}/sendMessage?{encoded_querystring}' |
|
|
|
|
send_message_url = f'https://api.telegram.org/bot{bot_token}/sendMessage?{encoded_querystring}' |
|
|
|
|
|
|
|
|
|
response = requests.get(send_message_url) |
|
|
|
|
result = response.json() |
|
|
|
@ -37,9 +37,9 @@ class TelegramPromoter(Promoter):
|
|
|
|
|
|
|
|
|
|
class VkontaktePromoter(Promoter): |
|
|
|
|
def promote(self): |
|
|
|
|
vk_login = os.getenv('VK_LOGIN') |
|
|
|
|
vk_password = os.getenv('VK_PASSWORD') |
|
|
|
|
vk_owner_id = os.getenv('VK_OWNER_ID') |
|
|
|
|
vk_login = promoter_secrets['VK_LOGIN'] |
|
|
|
|
vk_password = promoter_secrets['VK_PASSWORD'] |
|
|
|
|
vk_owner_id = promoter_secrets['VK_OWNER_ID'] |
|
|
|
|
|
|
|
|
|
import vk_api |
|
|
|
|
session = vk_api.VkApi(login=vk_login, |
|
|
|
@ -60,9 +60,9 @@ class OdnoklassnikiPromoter(Promoter):
|
|
|
|
|
from json import JSONEncoder |
|
|
|
|
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') |
|
|
|
|
ok_access_token = promoter_secrets['OK_ACCESS_TOKEN'] |
|
|
|
|
ok_application_key = promoter_secrets['OK_APPLICATION_KEY'] |
|
|
|
|
ok_application_secret_key = promoter_secrets['OK_APPLICATION_SECRET_KEY'] |
|
|
|
|
|
|
|
|
|
session = ok_api.OkApi(access_token=ok_access_token, |
|
|
|
|
application_key=ok_application_key, |
|
|
|
|