Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def schedule_cron(command, interval, crontab=None):
from crontab import CronTab, CronItem
if not os.path.exists(crontab):
with open(crontab, 'w'):
pass
if crontab:
c = CronTab(tabfile=crontab)
else:
c = CronTab(user=getpass.getuser())
job = CronItem.from_line(interval + ' ' + command, cron=c)
c.append(job)
c.write()
return c, job