Дополнение. Загрузка статистики работы на сервер.
parent
147e97c8a5
commit
81fd61ea0a
|
@ -1,16 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# Telegram chat reader v1.00
|
# Telegram chat reader v1.01
|
||||||
# 21/12/2021
|
# 22/12/2021
|
||||||
# https://t.me/ssleg © 2021
|
# https://t.me/ssleg © 2021
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from hashlib import md5
|
||||||
from os import path
|
from os import path
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import toml
|
import toml
|
||||||
|
from requests import post
|
||||||
from telethon import TelegramClient, functions, errors
|
from telethon import TelegramClient, functions, errors
|
||||||
|
|
||||||
import reader_module
|
import reader_module
|
||||||
|
@ -83,6 +85,26 @@ def get_db_chats_dict(curs):
|
||||||
return chats_dict
|
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():
|
def update_all():
|
||||||
client = TelegramClient('chat_reader', api_id, api_hash)
|
client = TelegramClient('chat_reader', api_id, api_hash)
|
||||||
|
@ -107,6 +129,7 @@ def update_all():
|
||||||
summary_read += await reader_module.read_chat(key)
|
summary_read += await reader_module.read_chat(key)
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
|
stat_upload(summary_read)
|
||||||
levent = f'Всего прочитано: {set_num_printable(summary_read)}.'
|
levent = f'Всего прочитано: {set_num_printable(summary_read)}.'
|
||||||
print(levent)
|
print(levent)
|
||||||
logging.info(levent)
|
logging.info(levent)
|
||||||
|
@ -287,7 +310,8 @@ def add_new(chat_name):
|
||||||
entry)
|
entry)
|
||||||
con.commit()
|
con.commit()
|
||||||
await reader_module.init(client, con, cursor)
|
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:
|
except TypeError as e:
|
||||||
if str(e) == 'Cannot cast InputPeerUser to any kind of InputChannel.':
|
if str(e) == 'Cannot cast InputPeerUser to any kind of InputChannel.':
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
psycopg2~=2.8.6
|
psycopg2~=2.8.6
|
||||||
toml~=0.10.2
|
toml~=0.10.2
|
||||||
Telethon~=1.24.0
|
Telethon~=1.24.0
|
||||||
|
requests~=2.23.0
|
Loading…
Reference in New Issue