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))
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

@ -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()

Loading…
Cancel
Save