From 27d5c9e4110bad476236d21d890935fc9995158f Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 9 Dec 2022 23:27:52 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D1=8B=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=D0=B8=20=D0=B2=20=D1=82=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BC-=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=20#8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cms/views.py | 16 ++++++++++++++++ .../__pycache__/settings.cpython-311.pyc | Bin 2659 -> 0 bytes crossposting_backend/__pycache__/urls.cpython-311.pyc | Bin 1074 -> 0 bytes crossposting_backend/settings.py | 5 +++++ 4 files changed, 21 insertions(+) delete mode 100644 crossposting_backend/__pycache__/settings.cpython-311.pyc delete mode 100644 crossposting_backend/__pycache__/urls.cpython-311.pyc diff --git a/cms/views.py b/cms/views.py index dc03680..71b7c3d 100644 --- a/cms/views.py +++ b/cms/views.py @@ -11,8 +11,24 @@ from cms.models import Article @method_decorator(csrf_exempt, name='dispatch') class ArticleView(View): + def _send_to_channel(self, article: Article): + bot_token = os.getenv('TELEGRAM_BOT_TOKEN') + channel_id = os.getenv('TELEGRAM_CHAT_ID') + + long_text = f'{article.title}\n{article.body}' + + send_message_url = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={channel_id}&text={long_text}' + + response = requests.get(send_message_url) + result = response.json() + if result['ok']: + print('Мы послали сообщение, ура!') + else: + print('Похоже, нас послали доделывать приложение :-(') + def post(self, request): article_data = JSONDecoder().decode(request.body.decode()) article = Article.objects.create(**article_data) + self._send_to_channel(article) response = {'ok': True} return JsonResponse(response) \ No newline at end of file diff --git a/crossposting_backend/__pycache__/settings.cpython-311.pyc b/crossposting_backend/__pycache__/settings.cpython-311.pyc deleted file mode 100644 index 1d7bc387023de38297bb92cb72955090021373cd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2659 zcmb6b%Wm67aH+RtNtP8Sc9IrgkT$WLnsQ+0(Kbj!OSB_ImQ+!WTV4oSyO!zjp>U}< z=1IpE=%GLl?IDLEhZIFVqQBr2L2K}2pqKVWAh(=4)Wa5J19b^%I6Lo|o!Qkd$z&YC z^GETA#%~FP{_+=tC(=jW{SC;E2qOt$1_v}o4@dz91rQ04;4229*YN8-KZgd`@b?ug zULO&5!UOaelOi}MMR7=qHIX#dL^%ACk>c=;z;_%+r33~J4q=}cf61r}9)A&PGEx#J zq!do#6p7#oXB;7%ei2X^X#!8;3`kAlb6q&qh38eK8IscYf;5Szr40Bx2fryiBb~<= zr3?6yh_aWJPa&OnVMj5VCQFHJt45QuTc*V}ER)ifNqvgEsWhGt1G6p5+#wB{i^o@q zK`g~4nBClCuj8(Pc?IjL!BShX?7rl6woSnR+xM`<-Q<=)dj%ZmrbSrQ0AIRdtER!i zYj3OIUDe1Z5DbZL+jfh7mdjzYLAjofK?Ds`&k-XB26MLAQX4ckh(6adZ*LQJtF39Q zrc#?Vw~n(@AQ9lI7W+)m+JyceUl!RKa`cbCxmm^yRTX>NS?*UsH7IGcEi(UP*S^!d zb9-Sii*;*u(OQ^O<{vcdommwx%u#*m`NGb#yUq5k?FHG&UcEAFH|yDmGu1Q0HB7^{ z)J?8iROj3%wGAFGj}UzoV%YXxi%@5Jgh>gdQ09{i9T-XzG%k&5*sw7Te>-S4>dg1K zx{9$zb`^_o-8@x$j}!fb0a-iZIZLC)`tG?QeX&Oy(#oE60z0jn2AA)C{zH^nTU;K% zW0mXZUfjjX0z@n#7<~!^&&D@(pR-J|ziFZ9Lh5DS~0(zFM&q zom5(W*V7@ri>J*T*S0k3bUUi0P`YbcScY>&#a(yYIwclw`-9xJ ziKyzTruc*MxF=y+&i%7mT2l>GZ|fyuH0|wU{V&d{-y5K6KgMGN56)_!+}4SuHcnay z6Jx$j-QapX??mDBhe66YANI{cC3O=MjdIIs69&y(QHh4j*=aW_%W$yEvKwu|@u{hs zRuD?-#$?$)a(uc)sHr_8ZlndLjbXd7WnL8gZFl3Mkgo}K`H}Fo8!iaT>#J^(FO@1A zLP3655$mFxDwf4MkbnTaBD(RlVxdqHHu#$0CTf*RU0$!1@|E(6J60FgswKWIh;DjA zTrK+YrDC4<+sYj)@O9pIE4nlMdi|kX73jufi7&6N^Q(fKuM`9@ zSX>iisRAt%TZe#)H}96+h>z7Jh`bJ#^S*aCQxI18^-^61%N2R0D3l7nqIdqK@?Oks zn>xu^1e52vs%19e$bj+#=3l@xSKYI>P2*^JTJPr?aKj$mR$OcEee51=MO!2Ht!v=J z|06>MfL@Sc7%vcKLLTzL3}PD;g40n*8`RU%9^mQ*BOoN~g zg5j>YiM$&lRQjJcE%3JCpxi1NG{?f VP-+^2kE08>_EDzyS|33<{{=b9cT@lX diff --git a/crossposting_backend/__pycache__/urls.cpython-311.pyc b/crossposting_backend/__pycache__/urls.cpython-311.pyc deleted file mode 100644 index 40faf63425dd833a7001d99db5bfe658c6a889ff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1074 zcma)5&ubJh6wb`fZtK+6s|S%t54!_(LPal&Kagr^LA0p7>}8srWOrwsOok+@tswO1 zQLx~DposrW1rIV;Pu>=K+mkP|GqQ?8Gn4QVUcUFe@4b9lUG))+&d&RI<|6dNZtCGx z#@QYi9}q)5#2n_Pj&OUfW9>%T5MIx7kc+s-JnoL0_2qG^wmt&x7nt)gbb3py`3wau z`UVbTCAH3_Hc2*&`ZRvQGlut{KEhiv8zjStq9&1`@Ld@xaIPL1Iz(+4th%rV{+XkgvnTkY)rGE%#|GT z*o3hZglFVtxJiu6lUNh$Odz}_{=-8m084lM?MW6}cJr_$=w^uTGlpq~6Ol`0x)=|X z6j&TZG|#KU1^*kBf0;5Qu#h2Kg=9yac6+1BYa|8Vz!??%PTSh;z~4%#*4O)x7+XO7 z9}8(lTv;MvDO62o2e3-^=VW93L#iVS(h2@zw4250gh4eygfgB@Erw#&`s|j%V4wo! zvA(<$;6Wv2cP`hw9HAAwCRzDzl%kxQZ9kPm0s_{N+V-HtZ3lt>)3#*b6iv!Rl7Zn_ z#b39|EqNR)7fVqD{SigQT15#mF)Hb+2HY%G7I-TAS_)4mh8LbCUaTw>^D{cLv1U(* zEgVst@k6qw