-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (39 loc) · 1.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import os
import subprocess
import sys
from datetime import datetime
import click
from dgt_parser import DGTParser
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
logging.basicConfig(level=LOGLEVEL)
logging.getLogger().addHandler(logging.StreamHandler())
fileHandler = logging.FileHandler("/home/genis/projects/dgt_test_results/output.txt")
logging.getLogger().addHandler(fileHandler)
def send_message(message):
subprocess.Popen(['notify-send', '-t', '10000', message])
return
@click.command()
@click.option('--cron/--no-cron', default=False)
def main(cron):
parser = DGTParser()
try:
logging.info(f'Starting at {datetime.now()}...')
results = parser.get_results()
if results:
logging.info('Results found.\n')
if not cron:
for item in results:
logging.info(f'{item} : {results[item]}')
else:
# Send notification
send_message('DGT Results found! Check the logs')
sys.exit(0)
else:
logging.info('Results not found')
sys.exit(0)
except Exception as e:
logging.error(f'Error found: {e}')
sys.exit(1)
if __name__ == '__main__':
main()