How to use the crontab.CronItem.from_line function in crontab

To help you get started, we’ve selected a few crontab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timkpaine / paperboy / paperboy / scheduler / cron / __init__.py View on Github external
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