From 81fd61ea0af856bc8ea81a39fac4b99239567e25 Mon Sep 17 00:00:00 2001 From: ssleg <1537206@mail.ru> Date: Wed, 22 Dec 2021 07:35:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5.=20=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat_reader.py | 30 +++++++++++++++++++++++++++--- requirements.txt | 3 ++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/chat_reader.py b/chat_reader.py index 9b1a04e..3d28e3d 100755 --- a/chat_reader.py +++ b/chat_reader.py @@ -1,16 +1,18 @@ #!/usr/bin/env python3 -# Telegram chat reader v1.00 -# 21/12/2021 +# Telegram chat reader v1.01 +# 22/12/2021 # https://t.me/ssleg © 2021 import logging +from hashlib import md5 from os import path from sys import argv import psycopg2 import toml +from requests import post from telethon import TelegramClient, functions, errors import reader_module @@ -83,6 +85,26 @@ def get_db_chats_dict(curs): return chats_dict +# загрузка статистики работы на сервер +def stat_upload(read_mess): + request_headers = { + 'Accept': 'application/json, text/plain, */*', + 'Content-Type': 'application/json; charset=utf-8' + } + # noinspection HttpUrlsUsage + stat_upload_url = 'http://188.124.50.148/stat_up' + finger = str(api_id) + api_hash + hash_md5 = md5(finger.encode()) + request_json = {'protocol_version': '1.2', 'application': 'Chat Reader', 'app_version': get_version(), + 'uptime': 0, 'errors': 0, 'fingerprint': hash_md5.hexdigest(), 'users': 0, 'work_count': read_mess} + try: + post(stat_upload_url, headers=request_headers, json=request_json, timeout=5) + + except Exception as e: + levent = 'ошибка в http запросе: ' + str(e) + logging.error(levent) + + # обновление всех чатов def update_all(): client = TelegramClient('chat_reader', api_id, api_hash) @@ -107,6 +129,7 @@ def update_all(): summary_read += await reader_module.read_chat(key) print('') + stat_upload(summary_read) levent = f'Всего прочитано: {set_num_printable(summary_read)}.' print(levent) logging.info(levent) @@ -287,7 +310,8 @@ def add_new(chat_name): entry) con.commit() await reader_module.init(client, con, cursor) - await reader_module.read_chat(chat_id) + readed = await reader_module.read_chat(chat_id) + stat_upload(readed) except TypeError as e: if str(e) == 'Cannot cast InputPeerUser to any kind of InputChannel.': diff --git a/requirements.txt b/requirements.txt index 1fd3240..736a266 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ psycopg2~=2.8.6 toml~=0.10.2 -Telethon~=1.24.0 \ No newline at end of file +Telethon~=1.24.0 +requests~=2.23.0 \ No newline at end of file