New func in parser and vodynoi can send xlsx to tg
This commit is contained in:
parent
d0e87dc9c5
commit
0a52d81b40
11 changed files with 563 additions and 12 deletions
2
parser/.env_old
Normal file
2
parser/.env_old
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
LOGIN=l_salnikov@internet.ru
|
||||||
|
PASSWORD=}v]CT]Q"_g7>4H%
|
||||||
1
parser/.~lock.tmp.xlsx#
Normal file
1
parser/.~lock.tmp.xlsx#
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
,q,q,26.11.2024 20:34,file:///home/q/.config/libreoffice/4;
|
||||||
|
|
@ -29,16 +29,13 @@ def get_token():
|
||||||
#Device parsing
|
#Device parsing
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
codes_to_search = [
|
|
||||||
"P16385", "P16386", "P16387", "P16388", "P16389", "P16390", "P16391",
|
|
||||||
"P16392", "P16393", "P16394", "P16395", "P16396", "P16397", "P16398"
|
|
||||||
]
|
|
||||||
token = get_token()
|
token = get_token()
|
||||||
if not token:
|
if not token:
|
||||||
print("Не удалось получить токен. Завершаем работу.")
|
print("Не удалось получить токен. Завершаем работу.")
|
||||||
return
|
return
|
||||||
|
|
||||||
device_id = "459205"
|
device_id = "296613"
|
||||||
headers = {'Authorization': token}
|
headers = {'Authorization': token}
|
||||||
data = json.dumps({'filter': ''})
|
data = json.dumps({'filter': ''})
|
||||||
|
|
||||||
|
|
@ -51,14 +48,14 @@ def main():
|
||||||
#print(req.text)
|
#print(req.text)
|
||||||
#print("Response structure:", json.dumps(nswer, indent=2))
|
#print("Response structure:", json.dumps(nswer, indent=2))
|
||||||
nwer = req.json() # Store the response in 'nwer'
|
nwer = req.json() # Store the response in 'nwer'
|
||||||
|
print(req.text)
|
||||||
# Check and process the parameters list
|
# Check and process the parameters list
|
||||||
if 'parameters' in nwer and isinstance(nwer['parameters'], list):
|
#if 'parameters' in nwer and isinstance(nwer['parameters'], list):
|
||||||
for item in nwer['parameters']:
|
# for item in nwer['parameters']:
|
||||||
if isinstance(item, dict) and 'code' in item and item['code'] in codes_to_search:
|
# if isinstance(item, dict) and 'code' in item and item['code']: #and item['value'] > str('0') and item['value'] < str('5000'):
|
||||||
print(f"Code: {item['code']}, Value: {item['value']}")
|
# print(f"Name: {item['name']}, Code: {item['code']}, Value: {item['value']}")
|
||||||
else:
|
# else:
|
||||||
print("Unexpected response format or 'parameters' key is missing.")
|
# print("Unexpected response format or 'parameters' key is missing.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
65
parser/device_parser_P.py
Normal file
65
parser/device_parser_P.py
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Load information for owencloud and telegram
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
#Get Token for OwenCloud
|
||||||
|
def get_token():
|
||||||
|
login = os.getenv("LOGIN")
|
||||||
|
password = os.getenv("PASSWORD")
|
||||||
|
if not login or not password:
|
||||||
|
raise ValueError("Логин или пароль не заданы в .env")
|
||||||
|
|
||||||
|
data = {'login': login, 'password': password}
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
req = requests.post("https://api.owencloud.ru/v1/auth/open/", json=data, headers=headers)
|
||||||
|
if req.status_code == 200:
|
||||||
|
answer = req.json()
|
||||||
|
token = "Bearer " + answer["token"]
|
||||||
|
return token
|
||||||
|
else:
|
||||||
|
print(f"Ошибка авторизации: {req.status_code}, {req.text}")
|
||||||
|
return None
|
||||||
|
#Device parsing
|
||||||
|
def main():
|
||||||
|
|
||||||
|
codes_to_search = [
|
||||||
|
"P16385", "P16386", "P16387", "P16388", "P16389", "P16390", "P16391",
|
||||||
|
"P16392", "P16393", "P16394", "P16395", "P16396", "P16397", "P16398"
|
||||||
|
]
|
||||||
|
token = get_token()
|
||||||
|
if not token:
|
||||||
|
print("Не удалось получить токен. Завершаем работу.")
|
||||||
|
return
|
||||||
|
|
||||||
|
device_id = "459205"
|
||||||
|
headers = {'Authorization': token}
|
||||||
|
data = json.dumps({'filter': ''})
|
||||||
|
|
||||||
|
req = requests.post(f"https://api.owencloud.ru/v1/device/{device_id}", data=data, headers=headers)
|
||||||
|
if req.status_code != 200:
|
||||||
|
print(f"Ошибка запроса устройства: {req.status_code}, {req.text}")
|
||||||
|
return
|
||||||
|
|
||||||
|
#nswer = req.json()
|
||||||
|
#print(req.text)
|
||||||
|
#print("Response structure:", json.dumps(nswer, indent=2))
|
||||||
|
nwer = req.json() # Store the response in 'nwer'
|
||||||
|
|
||||||
|
# Check and process the parameters list
|
||||||
|
if 'parameters' in nwer and isinstance(nwer['parameters'], list):
|
||||||
|
for item in nwer['parameters']:
|
||||||
|
if isinstance(item, dict) and 'code' in item and item['code'] in codes_to_search:
|
||||||
|
print(f"Code: {item['code']}, Value: {item['value']}")
|
||||||
|
else:
|
||||||
|
print("Unexpected response format or 'parameters' key is missing.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
96
parser/devices_parser_chage.py
Normal file
96
parser/devices_parser_chage.py
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Load information for owencloud and telegram
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# Get Token for OwenCloud
|
||||||
|
def get_token():
|
||||||
|
login = os.getenv("LOGIN")
|
||||||
|
password = os.getenv("PASSWORD")
|
||||||
|
if not login or not password:
|
||||||
|
raise ValueError("Логин или пароль не заданы в .env")
|
||||||
|
|
||||||
|
data = {'login': login, 'password': password}
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
req = requests.post("https://api.owencloud.ru/v1/auth/open/", json=data, headers=headers)
|
||||||
|
if req.status_code == 200:
|
||||||
|
answer = req.json()
|
||||||
|
token = "Bearer " + answer["token"]
|
||||||
|
return token
|
||||||
|
else:
|
||||||
|
print(f"Ошибка авторизации: {req.status_code}, {req.text}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
# Load previous values from a file
|
||||||
|
def load_previous_values(file_path="previous_values.json"):
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
with open(file_path, "r") as file:
|
||||||
|
return json.load(file)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
# Save current values to a file
|
||||||
|
def save_current_values(data, file_path="previous_values.json"):
|
||||||
|
with open(file_path, "w") as file:
|
||||||
|
json.dump(data, file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
# Device parsing and comparison
|
||||||
|
def monitor_changes():
|
||||||
|
previous_values = load_previous_values()
|
||||||
|
token = get_token()
|
||||||
|
if not token:
|
||||||
|
print("Не удалось получить токен. Завершаем работу.")
|
||||||
|
return
|
||||||
|
|
||||||
|
device_id = "459205"
|
||||||
|
headers = {'Authorization': token}
|
||||||
|
data = json.dumps({'filter': ''})
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
req = requests.post(f"https://api.owencloud.ru/v1/device/{device_id}", data=data, headers=headers)
|
||||||
|
if req.status_code != 200:
|
||||||
|
print(f"Ошибка запроса устройства: {req.status_code}, {req.text}")
|
||||||
|
time.sleep(60) # Подождать минуту и попробовать снова
|
||||||
|
continue
|
||||||
|
|
||||||
|
nwer = req.json()
|
||||||
|
current_values = {}
|
||||||
|
|
||||||
|
# Check and process the parameters list
|
||||||
|
if 'parameters' in nwer and isinstance(nwer['parameters'], list):
|
||||||
|
for item in nwer['parameters']:
|
||||||
|
if isinstance(item, dict) and 'code' in item and item['code']:
|
||||||
|
code = item['code']
|
||||||
|
value = item['value']
|
||||||
|
current_values[code] = value
|
||||||
|
|
||||||
|
# Compare with previous values
|
||||||
|
if code in previous_values:
|
||||||
|
if previous_values[code] != value:
|
||||||
|
print(f"Изменение: {item['name']} (Code: {code}): {previous_values[code]} -> {value}")
|
||||||
|
else:
|
||||||
|
print(f"Новый параметр: {item['name']} (Code: {code}), Value: {value}")
|
||||||
|
|
||||||
|
# Save current values for future comparison
|
||||||
|
save_current_values(current_values)
|
||||||
|
previous_values = current_values
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Ошибка в процессе мониторинга: {e}")
|
||||||
|
|
||||||
|
# Pause for 1 minute
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
monitor_changes()
|
||||||
28
parser/example_json_to_xlsx.json
Normal file
28
parser/example_json_to_xlsx.json
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"from_date": "30-07-2024",
|
||||||
|
"hs": "00",
|
||||||
|
"ms": "00",
|
||||||
|
"ss": "00",
|
||||||
|
"till_date": "28-11-2024",
|
||||||
|
"he": "17",
|
||||||
|
"me": "22",
|
||||||
|
"se": "05",
|
||||||
|
"page_size": "15",
|
||||||
|
"show_codes": "1",
|
||||||
|
"parameters": "[13716435,13716441,13716465,13716447,13716453,13716471,13716477,13716483,13716495,13716489,13716501]", #id девайсов
|
||||||
|
"filename": "Таблицы [26-11-2024 17-24-00] ПБКТ-3 - Шача.xlsx",
|
||||||
|
"where": "forward",
|
||||||
|
"token": "4xNpBShAUHqwIAfd0fkR3sZ6SWTe-r3r",
|
||||||
|
"deviceId": 296613,
|
||||||
|
"from": 1722297600000, # date -d @1722297600|000
|
||||||
|
"to": 1732814525000, # date -d @1732814525|000
|
||||||
|
"lang": "ru-RU",
|
||||||
|
"translations": {
|
||||||
|
"report": "Отчет",
|
||||||
|
"period": "Период",
|
||||||
|
"device": "Устройство",
|
||||||
|
"time": "Дата/время",
|
||||||
|
"reportname": "Таблица",
|
||||||
|
"error": "Ошибка"
|
||||||
|
}
|
||||||
|
}
|
||||||
78
parser/gen_tabel.py
Normal file
78
parser/gen_tabel.py
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
|
# Load information for owencloud and telegram
|
||||||
|
load_dotenv()
|
||||||
|
to = int(datetime.now().timestamp()* 1000)
|
||||||
|
from_ = int((datetime.now() - relativedelta(months=3)).timestamp()* 1000)
|
||||||
|
print(f"to: {to}")
|
||||||
|
print(f"from: {from_}")
|
||||||
|
#Get Token for OwenCloud
|
||||||
|
|
||||||
|
def get_token():
|
||||||
|
login = os.getenv("LOGIN")
|
||||||
|
password = os.getenv("PASSWORD")
|
||||||
|
if not login or not password:
|
||||||
|
raise ValueError("Логин или пароль не заданы в .env")
|
||||||
|
|
||||||
|
data = {'login': login, 'password': password}
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
req = requests.post("https://api.owencloud.ru/v1/auth/open/", json=data, headers=headers)
|
||||||
|
if req.status_code == 200:
|
||||||
|
answer = req.json()
|
||||||
|
token = (answer["token"])
|
||||||
|
print(token)
|
||||||
|
return token
|
||||||
|
else:
|
||||||
|
print(f"Ошибка авторизации: {req.status_code}, {req.text}")
|
||||||
|
return None
|
||||||
|
#Device parsing
|
||||||
|
def main():
|
||||||
|
token = get_token()
|
||||||
|
if not token:
|
||||||
|
print("Не удалось получить токен. Завершаем работу.")
|
||||||
|
return
|
||||||
|
|
||||||
|
device_id = "296613"
|
||||||
|
headers = {'Authorization': token}
|
||||||
|
#data = json.dumps({'filter': ''})
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'query': f'''{{
|
||||||
|
"parameters":"[13716435,13716441,13716465,13716447,13716453,13716471,13716477,13716483,13716495,13716489,13716501]",
|
||||||
|
"filename":"tmp.xlsx",
|
||||||
|
"token":"{token}",
|
||||||
|
"deviceId":296613,
|
||||||
|
"from": {from_},
|
||||||
|
"to": {to},
|
||||||
|
"translations":{{
|
||||||
|
"report":"Отчет",
|
||||||
|
"period":"Период",
|
||||||
|
"device":"Устройство",
|
||||||
|
"time":"Дата/время",
|
||||||
|
"reportname":"Таблица",
|
||||||
|
"error":"Ошибка"
|
||||||
|
}}
|
||||||
|
}}'''
|
||||||
|
}
|
||||||
|
|
||||||
|
req = requests.post(f"https://web.owencloud.ru/device/table-export", data=data, headers=headers)
|
||||||
|
if req.status_code != 200:
|
||||||
|
print(f"Ошибка запроса устройства: {req.status_code}, {req.text}")
|
||||||
|
return
|
||||||
|
|
||||||
|
#nswer = req.json()
|
||||||
|
print("Now i save fia")
|
||||||
|
with open('tmp.xlsx', 'wb') as ff:
|
||||||
|
ff.write(req.content)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
186
parser/previous_values.json
Normal file
186
parser/previous_values.json
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
{
|
||||||
|
"P16496": "0",
|
||||||
|
"P16511": "0",
|
||||||
|
"P16512": "0",
|
||||||
|
"P16513": "0",
|
||||||
|
"P16514": "0",
|
||||||
|
"P16515": "0",
|
||||||
|
"P16516": "0",
|
||||||
|
"P16517": "0",
|
||||||
|
"P16518": "0",
|
||||||
|
"P16519": "0",
|
||||||
|
"P16520": "0",
|
||||||
|
"P16521": "0",
|
||||||
|
"P16522": "0",
|
||||||
|
"P16523": "0",
|
||||||
|
"P16531": "0",
|
||||||
|
"P16529": "0",
|
||||||
|
"P16530": "0",
|
||||||
|
"P16528": "0",
|
||||||
|
"P16412": "0",
|
||||||
|
"P16427": "0",
|
||||||
|
"P16428": "0",
|
||||||
|
"P16429": "0",
|
||||||
|
"P16430": "0",
|
||||||
|
"P16431": "0",
|
||||||
|
"P16432": "0",
|
||||||
|
"P16433": "0",
|
||||||
|
"P16434": "0",
|
||||||
|
"P16435": "0",
|
||||||
|
"P16436": "0",
|
||||||
|
"P16437": "0",
|
||||||
|
"P16438": "0",
|
||||||
|
"P16439": "388",
|
||||||
|
"P16441": "0",
|
||||||
|
"P16442": "0",
|
||||||
|
"P16443": "0",
|
||||||
|
"P16444": "0",
|
||||||
|
"P16445": "0",
|
||||||
|
"P16446": "0",
|
||||||
|
"P16447": "0",
|
||||||
|
"P16448": "0",
|
||||||
|
"P16449": "0",
|
||||||
|
"P16450": "0",
|
||||||
|
"P16451": "0",
|
||||||
|
"P16452": "0",
|
||||||
|
"P16453": "0",
|
||||||
|
"P16454": "86",
|
||||||
|
"P16539": "0",
|
||||||
|
"P16537": "0",
|
||||||
|
"P16538": "0",
|
||||||
|
"P16536": "0",
|
||||||
|
"P16497": "0",
|
||||||
|
"P16498": "0",
|
||||||
|
"P16499": "0",
|
||||||
|
"P16500": "0",
|
||||||
|
"P16501": "0",
|
||||||
|
"P16502": "0",
|
||||||
|
"P16503": "0",
|
||||||
|
"P16504": "0",
|
||||||
|
"P16505": "0",
|
||||||
|
"P16506": "0",
|
||||||
|
"P16507": "0",
|
||||||
|
"P16508": "0",
|
||||||
|
"P16509": "0",
|
||||||
|
"P16510": "0",
|
||||||
|
"P16555": "0",
|
||||||
|
"P16556": "2",
|
||||||
|
"P16557": "2",
|
||||||
|
"P16558": "2",
|
||||||
|
"P16559": "0",
|
||||||
|
"P16560": "0",
|
||||||
|
"P16561": "2",
|
||||||
|
"P16562": "2",
|
||||||
|
"P16563": "2",
|
||||||
|
"P16564": "2",
|
||||||
|
"P16565": "2",
|
||||||
|
"P16566": "0",
|
||||||
|
"P16567": "0",
|
||||||
|
"P16568": "1",
|
||||||
|
"P16535": "0",
|
||||||
|
"P16532": "1",
|
||||||
|
"P16534": "1",
|
||||||
|
"P16533": "0",
|
||||||
|
"P16541": "0",
|
||||||
|
"P16542": "192",
|
||||||
|
"P16543": "192",
|
||||||
|
"P16544": "192",
|
||||||
|
"P16545": "0",
|
||||||
|
"P16546": "0",
|
||||||
|
"P16547": "192",
|
||||||
|
"P16548": "192",
|
||||||
|
"P16549": "192",
|
||||||
|
"P16550": "192",
|
||||||
|
"P16551": "192",
|
||||||
|
"P16552": "0",
|
||||||
|
"P16553": "0",
|
||||||
|
"P16554": "4",
|
||||||
|
"P16413": "5780",
|
||||||
|
"P16414": "5763",
|
||||||
|
"P16415": "5770",
|
||||||
|
"P16416": "5776",
|
||||||
|
"P16417": "0",
|
||||||
|
"P16418": "5767",
|
||||||
|
"P16419": "5768",
|
||||||
|
"P16420": "5806",
|
||||||
|
"P16421": "5790",
|
||||||
|
"P16422": "5799",
|
||||||
|
"P16423": "5802",
|
||||||
|
"P16424": "5791",
|
||||||
|
"P16425": "5812",
|
||||||
|
"P16426": "5663",
|
||||||
|
"P16525": "0",
|
||||||
|
"P16524": "0",
|
||||||
|
"P16526": "0",
|
||||||
|
"P16527": "1",
|
||||||
|
"P16440": "0",
|
||||||
|
"P16455": "0",
|
||||||
|
"P16456": "0",
|
||||||
|
"P16457": "0",
|
||||||
|
"P16458": "0",
|
||||||
|
"P16459": "0",
|
||||||
|
"P16460": "0",
|
||||||
|
"P16461": "0",
|
||||||
|
"P16462": "0",
|
||||||
|
"P16463": "0",
|
||||||
|
"P16464": "0",
|
||||||
|
"P16465": "0",
|
||||||
|
"P16466": "0",
|
||||||
|
"P16467": "3000",
|
||||||
|
"P16385": "0",
|
||||||
|
"P16386": "0",
|
||||||
|
"P16387": "0",
|
||||||
|
"P16388": "0",
|
||||||
|
"P16389": "0",
|
||||||
|
"P16390": "0",
|
||||||
|
"P16391": "0",
|
||||||
|
"P16392": "0",
|
||||||
|
"P16393": "0",
|
||||||
|
"P16394": "0",
|
||||||
|
"P16395": "0",
|
||||||
|
"P16396": "0",
|
||||||
|
"P16397": "0",
|
||||||
|
"P16398": "5000",
|
||||||
|
"P16469": "3",
|
||||||
|
"P16470": "3",
|
||||||
|
"P16471": "3",
|
||||||
|
"P16472": "3",
|
||||||
|
"P16473": "0",
|
||||||
|
"P16474": "3",
|
||||||
|
"P16475": "3",
|
||||||
|
"P16476": "3",
|
||||||
|
"P16477": "3",
|
||||||
|
"P16478": "3",
|
||||||
|
"P16479": "3",
|
||||||
|
"P16480": "3",
|
||||||
|
"P16481": "3",
|
||||||
|
"P16482": "1",
|
||||||
|
"P16468": "3105",
|
||||||
|
"P16483": "3105",
|
||||||
|
"P16484": "3105",
|
||||||
|
"P16485": "3105",
|
||||||
|
"P16486": "0",
|
||||||
|
"P16487": "3105",
|
||||||
|
"P16488": "3105",
|
||||||
|
"P16489": "3105",
|
||||||
|
"P16490": "3105",
|
||||||
|
"P16491": "3105",
|
||||||
|
"P16492": "3105",
|
||||||
|
"P16493": "3105",
|
||||||
|
"P16494": "3105",
|
||||||
|
"P16495": "3105",
|
||||||
|
"P16384": "5000",
|
||||||
|
"P16399": "4800",
|
||||||
|
"P16400": "5000",
|
||||||
|
"P16401": "5000",
|
||||||
|
"P16402": "0",
|
||||||
|
"P16403": "5000",
|
||||||
|
"P16404": "5000",
|
||||||
|
"P16405": "5000",
|
||||||
|
"P16406": "5000",
|
||||||
|
"P16407": "5000",
|
||||||
|
"P16408": "5000",
|
||||||
|
"P16409": "5000",
|
||||||
|
"P16410": "5000",
|
||||||
|
"P16411": "5000"
|
||||||
|
}
|
||||||
BIN
parser/tmp.xlsx
Normal file
BIN
parser/tmp.xlsx
Normal file
Binary file not shown.
98
vodynoi/gen_tabel.py
Normal file
98
vodynoi/gen_tabel.py
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
|
|
||||||
|
# Load information for owencloud and telegram
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
to = int(datetime.now().timestamp()* 1000)
|
||||||
|
from_ = int((datetime.now() - relativedelta(months=3)).timestamp()* 1000)
|
||||||
|
to_formatted = (datetime.now())
|
||||||
|
from_formatted = to_formatted - relativedelta(months=3)
|
||||||
|
|
||||||
|
def send_telegram():
|
||||||
|
token = os.getenv("TELEGRAM_TOKEN")
|
||||||
|
channel_id = os.getenv("TELEGRAM_CHANNEL_ID")
|
||||||
|
if not token or not channel_id:
|
||||||
|
raise ValueError("Telegram токен или ID канала не заданы в .env")
|
||||||
|
|
||||||
|
url = f"https://api.telegram.org/bot{token}/sendDocument"
|
||||||
|
comment = f"С: {from_formatted}\nДо: {to_formatted}"
|
||||||
|
with open('tmp.xlsx', 'rb') as file:
|
||||||
|
r = requests.post(url, data={
|
||||||
|
"chat_id": channel_id,
|
||||||
|
"caption": comment
|
||||||
|
}, files={
|
||||||
|
"document": file
|
||||||
|
})
|
||||||
|
print(r.text)
|
||||||
|
if r.status_code != 200:
|
||||||
|
raise Exception(f"Ошибка отправки в Telegram: {r.text}")
|
||||||
|
def get_token():
|
||||||
|
login = os.getenv("LOGIN")
|
||||||
|
password = os.getenv("PASSWORD")
|
||||||
|
if not login or not password:
|
||||||
|
raise ValueError("Логин или пароль не заданы в .env")
|
||||||
|
|
||||||
|
data = {'login': login, 'password': password}
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
req = requests.post("https://api.owencloud.ru/v1/auth/open/", json=data, headers=headers)
|
||||||
|
if req.status_code == 200:
|
||||||
|
answer = req.json()
|
||||||
|
token = (answer["token"])
|
||||||
|
return token
|
||||||
|
else:
|
||||||
|
print(f"Ошибка авторизации: {req.status_code}, {req.text}")
|
||||||
|
return None
|
||||||
|
#Device parsing
|
||||||
|
def main():
|
||||||
|
token = get_token()
|
||||||
|
if not token:
|
||||||
|
print("Не удалось получить токен. Завершаем работу.")
|
||||||
|
return
|
||||||
|
|
||||||
|
device_id = "296613"
|
||||||
|
headers = {'Authorization': token}
|
||||||
|
#data = json.dumps({'filter': ''})
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'query': f'''{{
|
||||||
|
"parameters":"[13716435,13716441,13716465,13716447,13716453,13716471,13716477,13716483,13716495,13716489,13716501]",
|
||||||
|
"filename":"tmp.xlsx",
|
||||||
|
"token":"{token}",
|
||||||
|
"deviceId":296613,
|
||||||
|
"from": {from_},
|
||||||
|
"to": {to},
|
||||||
|
"translations":{{
|
||||||
|
"report":"Отчет",
|
||||||
|
"period":"Период",
|
||||||
|
"device":"Устройство",
|
||||||
|
"time":"Дата/время",
|
||||||
|
"reportname":"Таблица",
|
||||||
|
"error":"Ошибка"
|
||||||
|
}}
|
||||||
|
}}'''
|
||||||
|
}
|
||||||
|
|
||||||
|
req = requests.post(f"https://web.owencloud.ru/device/table-export", data=data, headers=headers)
|
||||||
|
if req.status_code != 200:
|
||||||
|
print(f"Ошибка запроса устройства: {req.status_code}, {req.text}")
|
||||||
|
return
|
||||||
|
|
||||||
|
#nswer = req.json()
|
||||||
|
print("Now i save fia")
|
||||||
|
with open('tmp.xlsx', 'wb') as ff:
|
||||||
|
ff.write(req.content)
|
||||||
|
|
||||||
|
send_telegram()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
BIN
vodynoi/tmp.xlsx
Normal file
BIN
vodynoi/tmp.xlsx
Normal file
Binary file not shown.
Loading…
Reference in a new issue