From 9b74f36995ed6ce29f8555fedcc068a9a45e5e99 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Thu, 29 Dec 2022 22:57:37 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=83?= =?UTF-8?q?=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B0=D0=B5=D1=82=20=D0=B8=D0=B4=20=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=BF=D0=BF=D1=8B=20=D0=A2=D0=93=20#38?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 9 +++++++++ cms/management/commands/get_telegram_group_id.py | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .env.example create mode 100644 cms/management/commands/get_telegram_group_id.py diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..62a9203 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +TELEGRAM_BOT_TOKEN=fdaTTdf +TELEGRAM_CHAT_ID=-1 +JOOMLA_TOKEN=c2ddd +VK_LOGIN=user@mail.pro +VK_PASSWORD=123123 +VK_OWNER_ID=-2 +OK_ACCESS_TOKEN=aatk +OK_APPLICATION_KEY=FFCF +OK_APPLICATION_SECRET_KEY=GGD \ No newline at end of file diff --git a/cms/management/commands/get_telegram_group_id.py b/cms/management/commands/get_telegram_group_id.py new file mode 100644 index 0000000..ec6676b --- /dev/null +++ b/cms/management/commands/get_telegram_group_id.py @@ -0,0 +1,24 @@ +import requests +from django.core.management import BaseCommand + +from crossposting_backend.settings import promoter_secrets + + +class Command(BaseCommand): + + def handle(self, *args, **options): + bot_token = promoter_secrets['TELEGRAM_BOT_TOKEN'] + get_updates_url = f'https://api.telegram.org/bot{bot_token}/getUpdates' + response = requests.get(get_updates_url) + if response.ok: + json_body = response.json() + if json_body['ok']: + if 'result' in json_body and len(json_body['result']) > 0: + print(json_body['result'][0]['channel_post']['sender_chat']['id']) + else: + print('Нет обновлений') + else: + print(json_body['error_code']) + else: + print(response.status_code) + return 0