Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add id_chat telegram #820

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ dmypy.json
.pyre/

# Custom
config.yaml
#config.yaml
*.bak
507 changes: 507 additions & 0 deletions config.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plotmanager/library/parse/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _get_notifications_settings(config):
parameter_type='notification')

if 'notify_telegram' in notifications and notifications['notify_telegram']:
_check_parameters(parameter=notifications, expected_parameters=['telegram_token'],
_check_parameters(parameter=notifications, expected_parameters=['telegram_token','telegram_chat_id'],
parameter_type='notification')

if 'notify_twilio' in notifications and notifications['notify_twilio']:
Expand Down
20 changes: 18 additions & 2 deletions plotmanager/library/utilities/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
import time

import json

from datetime import datetime, timedelta

from plotmanager.library.parse.configuration import get_config_info
Expand All @@ -13,7 +15,7 @@
from plotmanager.library.utilities.jobs import load_jobs
from plotmanager.library.utilities.log import analyze_log_dates, check_log_progress, analyze_log_times
from plotmanager.library.utilities.notifications import send_notifications
from plotmanager.library.utilities.print import print_view, print_json
from plotmanager.library.utilities.print import print_view, print_json, get_job_data, print_notification
from plotmanager.library.utilities.processes import is_windows, get_manager_processes, get_running_plots, \
start_process, identify_drive, get_system_drives

Expand Down Expand Up @@ -153,9 +155,10 @@ def view(loop=True):
if drive in drives[key]:
continue
drives[key].append(drive)

iteration=59
while True:
running_work = {}
iteration=iteration+1
try:
analysis = analyze_log_dates(log_directory=log_directory, analysis=analysis)
jobs = load_jobs(config_jobs)
Expand All @@ -167,6 +170,19 @@ def view(loop=True):
print_view(jobs=jobs, running_work=running_work, analysis=analysis, drives=drives,
next_log_check=datetime.now() + timedelta(seconds=view_check_interval),
view_settings=view_settings, loop=loop)
if iteration > 120:
iteration = 0
# jobs2 = dict(jobs= get_job_data(jobs=jobs, running_work=running_work, view_settings=view_settings))
# send_notifications(
# title='Plot manager started',
# body=str(json.dumps(jobs2, separators=(',', ':'),indent=2)),
# settings=notification_settings,
# )
send_notifications(
title='Plot manager started',
body=print_notification(jobs=jobs, running_work=running_work, view_settings=view_settings),
settings=notification_settings,
)
if not loop:
break
time.sleep(view_check_interval)
Expand Down
1 change: 1 addition & 0 deletions plotmanager/library/utilities/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


def test_configuration(chia_location, notification_settings, instrumentation_settings):
print(chia_location)
if not os.path.exists(chia_location):
raise InvalidChiaLocationException('The chia_location in your config.yaml does not exist. Please confirm if '
'you have the right version. Also confirm if you have a space after the '
Expand Down
1 change: 1 addition & 0 deletions plotmanager/library/utilities/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def _send_notifications(title, body, settings):
if settings.get('notify_telegram') is True:
import telegram_notifier
notifier = telegram_notifier.TelegramNotifier(settings.get('telegram_token'), parse_mode="HTML")
notifier._chat_id=settings.get('telegram_chat_id')
notifier.send(body)

if settings.get('notify_ifttt') is True:
Expand Down
10 changes: 10 additions & 0 deletions plotmanager/library/utilities/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from plotmanager.library.utilities.processes import get_manager_processes

notification_text="\n| {} | {} | {} | {} | {} | {} |"


def _get_row_info(pid, running_work, view_settings, as_raw_values=False):
work = running_work[pid]
Expand Down Expand Up @@ -220,3 +222,11 @@ def print_view(jobs, running_work, analysis, drives, next_log_check, view_settin
if loop:
print(f"Next log check at {next_log_check.strftime('%Y-%m-%d %H:%M:%S')}")
print()
def print_notification(jobs, running_work, view_settings):
rows =get_job_data(jobs, running_work, view_settings)
return_value= "|id|type|"
for row in rows:
return_value=return_value+notification_text.format(row[0],row[1],row[6],row[7],row[9],row[10])

return return_value

2 changes: 1 addition & 1 deletion requirements-notification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ discord_notify==1.0.0
playsound==1.2.2
prometheus-client==0.10.1
python_pushover==0.4
telegram_notifier==0.2
telegram_notifier==0.3
requests==2.25.1