Adapt to older systemd and print debug info for YT notifications

master
Nikola Forró 4 years ago
parent 244b7a92bd
commit 971f805649

@ -130,7 +130,7 @@ class Bot(discord.Client):
await channel.send(embed=self.make_twitter_embed(tweet)) await channel.send(embed=self.make_twitter_embed(tweet))
async def process_youtube_event(self, data): 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', {}) entry = data.get('feed', {}).get('entry', {})
if entry.get('yt:channelId') != yt_channel_id: if entry.get('yt:channelId') != yt_channel_id:
return return

@ -21,21 +21,22 @@ storage_path = config.get('General', 'storage_path')
class Timer: class Timer:
@classmethod @classmethod
def schedule(cls, time, data): 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(( subprocess.run((
'/usr/bin/sudo',
'/usr/bin/systemd-run', '/usr/bin/systemd-run',
'--user', '--uid=nobody', '--gid=nobody',
'--working-directory={0}'.format(pathlib.Path(__file__).parent), *['--setenv={0}={1}'.format(k, v) for k, v in env],
'--timer-property=AccuracySec=1s', '--timer-property=AccuracySec=1s',
'--on-calendar={0}'.format(time.strftime('%Y-%m-%d %H:%M:%S UTC')), '--on-calendar={0}'.format(time.astimezone().strftime('%Y-%m-%d %H:%M:%S')),
'/usr/bin/python3', '/bin/sh', '-c', 'cd {0} && {1}'.format(pathlib.Path(__file__).parent, command)
__file__,
json.dumps(data)
)) ))
@classmethod @classmethod
def execute(cls, data): def execute(cls, data):
queue = persistqueue.SQLiteQueue(storage_path) queue = persistqueue.SQLiteQueue(storage_path)
queue.put(data) queue.put(('youtube', data))
queue.task_done() queue.task_done()

Loading…
Cancel
Save