-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (36 loc) · 1.19 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
50
51
52
53
import logging
import argparse
import time
import yaml
from ecmwf import EcmwfApi
from bot import PlotBot
def main():
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO,
)
logger = logging.getLogger(__name__)
parser = argparse.ArgumentParser()
parser.add_argument('--bot_token', \
dest='bot_token', \
type=str, \
help='unique token of bot (KEEP PRIVATE!)')
args = parser.parse_args()
with open('stations.yaml', 'r') as file:
station_config = yaml.safe_load(file)
bot = PlotBot(args.bot_token,station_config)
ecmwf = EcmwfApi(station_config)
logging.info('Enter infinite loop')
while True:
try:
if bot.has_new_subscribers_waiting():
bot.send_plots_to_new_subscribers(ecmwf.download_plots(bot.stations_of_new_subscribers()))
bot.broadcast(ecmwf.download_latest_plots())
except:
pass
snooze = 5
logging.debug(f'snooze {snooze}s ...')
time.sleep(snooze)
if __name__ == '__main__':
main()