-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.py
29 lines (25 loc) · 869 Bytes
/
schedule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Author : manho <manho30@outlook.my>
@Description : Cron job scheduler
@File : schedule.py
@IDE : PyCharm
@Date : 7/7/2023 23:25
"""
import os
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
from apscheduler.triggers.interval import IntervalTrigger
# delete ./musics/*.mp3 and ./thumbnail/*.jpg every 24 hours
def delete_files():
os.system('rm -rf ./musics/*.mp3')
os.system('rm -rf ./thumbnail/*.jpg')
# run every 24 hours
def run():
print('Cron job scheduler started...')
scheduler = BlockingScheduler()
scheduler.add_job(delete_files, CronTrigger.from_crontab('0 0 * * *'))
scheduler.start()
if __name__ == '__main__':
print('You should not run this file directly. Please run bot.py instead.')