diff options
Diffstat (limited to 'warmachine/addons/standup.py')
| -rw-r--r-- | warmachine/addons/standup.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py index 6ee6378..aa7fda6 100644 --- a/warmachine/addons/standup.py +++ b/warmachine/addons/standup.py | |||
| @@ -2,6 +2,7 @@ import asyncio | |||
| 2 | from datetime import datetime, timedelta | 2 | from datetime import datetime, timedelta |
| 3 | import functools | 3 | import functools |
| 4 | import json | 4 | import json |
| 5 | import os | ||
| 5 | from pprint import pformat | 6 | from pprint import pformat |
| 6 | 7 | ||
| 7 | from .base import WarMachinePlugin | 8 | from .base import WarMachinePlugin |
| @@ -20,6 +21,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 20 | !standup-schedules | 21 | !standup-schedules |
| 21 | !standup-waiting_replies | 22 | !standup-waiting_replies |
| 22 | """ | 23 | """ |
| 24 | SETTINGS_FILENAME = 'standup_schedules.json' | ||
| 23 | def __init__(self, *args, **kwargs): | 25 | def __init__(self, *args, **kwargs): |
| 24 | super().__init__(*args, **kwargs) | 26 | super().__init__(*args, **kwargs) |
| 25 | 27 | ||
| @@ -38,6 +40,15 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 38 | self.users_awaiting_reply = {} | 40 | self.users_awaiting_reply = {} |
| 39 | self.log.info('Loaded standup plugin') | 41 | self.log.info('Loaded standup plugin') |
| 40 | 42 | ||
| 43 | self.settings_file = os.path.join( | ||
| 44 | self.config_dir, self.SETTINGS_FILENAME) | ||
| 45 | |||
| 46 | if not os.path.exists(self.settings_file): | ||
| 47 | self.log.info('Creating standup config file: {}'.format( | ||
| 48 | self.settings_file)) | ||
| 49 | with open(self.settings_file, 'w') as f: | ||
| 50 | f.write('{}') | ||
| 51 | |||
| 41 | def on_connect(self, connection): | 52 | def on_connect(self, connection): |
| 42 | self.load_schedule(connection) | 53 | self.load_schedule(connection) |
| 43 | 54 | ||
| @@ -416,7 +427,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 416 | data[channel][key] = self.standup_schedules[channel][key] | 427 | data[channel][key] = self.standup_schedules[channel][key] |
| 417 | 428 | ||
| 418 | data = {connection.id: data} | 429 | data = {connection.id: data} |
| 419 | with open('/home/jason/.warmachine/standup_schedules.json', 'w') as f: | 430 | with open(self.settings_file, 'w') as f: |
| 420 | f.write(json.dumps(data)) | 431 | f.write(json.dumps(data)) |
| 421 | 432 | ||
| 422 | self.log.info('Schedules saved to disk') | 433 | self.log.info('Schedules saved to disk') |
| @@ -425,7 +436,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 425 | """ | 436 | """ |
| 426 | Load the channel schedules from a file. | 437 | Load the channel schedules from a file. |
| 427 | """ | 438 | """ |
| 428 | with open('/home/jason/.warmachine/standup_schedules.json', 'r') as f: | 439 | with open(self.settings_file, 'r') as f: |
| 429 | try: | 440 | try: |
| 430 | data = json.loads(f.read()) | 441 | data = json.loads(f.read()) |
| 431 | except Exception as e: | 442 | except Exception as e: |