diff --git a/bot.py b/bot.py index 7f4ed19..88bd9f1 100644 --- a/bot.py +++ b/bot.py @@ -130,7 +130,7 @@ class Bot(discord.Client): await channel.send(embed=self.make_twitter_embed(tweet)) async def process_youtube_event(self, data): - # TODO: log data for now + import json; print(json.dumps(data)) # FIXME: remove entry = data.get('feed', {}).get('entry', {}) if entry.get('yt:channelId') != yt_channel_id: return diff --git a/timer.py b/timer.py index d8a2ef6..d95f9c4 100644 --- a/timer.py +++ b/timer.py @@ -21,21 +21,22 @@ storage_path = config.get('General', 'storage_path') class Timer: @classmethod def schedule(cls, time, data): + command = '/usr/bin/python3 {0} \'{1}\''.format(__file__, json.dumps(data)) + env = ((k, v) for k, v in os.environ.items() if k.startswith('CHEDDAR_KNIGHT')) subprocess.run(( + '/usr/bin/sudo', '/usr/bin/systemd-run', - '--user', - '--working-directory={0}'.format(pathlib.Path(__file__).parent), + '--uid=nobody', '--gid=nobody', + *['--setenv={0}={1}'.format(k, v) for k, v in env], '--timer-property=AccuracySec=1s', - '--on-calendar={0}'.format(time.strftime('%Y-%m-%d %H:%M:%S UTC')), - '/usr/bin/python3', - __file__, - json.dumps(data) + '--on-calendar={0}'.format(time.astimezone().strftime('%Y-%m-%d %H:%M:%S')), + '/bin/sh', '-c', 'cd {0} && {1}'.format(pathlib.Path(__file__).parent, command) )) @classmethod def execute(cls, data): queue = persistqueue.SQLiteQueue(storage_path) - queue.put(data) + queue.put(('youtube', data)) queue.task_done()