-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
40 lines (30 loc) · 836 Bytes
/
main.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
30
31
32
33
34
35
36
37
38
39
40
#-*- coding: utf-8 -*-
"""
启动脚本
start 启动 crontab
stop 删除 crontab
"""
from Helper import log
# 获取启动参数
import sys, os
try:
if sys.argv[1] == 'stop':
os.system("crontab -r")
log("rm all the crontab")
exit(0)
except IndexError:
pass
except SystemExit:
raise
cnt_path = os.path.dirname(os.getcwd() + "/" + sys.argv[0])
SPIDER_FILE = "Spider.py"
POSTER_FILE = "Poster.py"
SPIDER_LOG = "spider.log"
POSTER_LOG = "poster.log"
SPIDER_CRON = "*/1 * * * * cd %s && python %s>>%s\n" % (cnt_path, SPIDER_FILE, SPIDER_LOG)
POSTER_CRON = "*/1 * * * * cd %s && python %s>>%s\n" % (cnt_path, POSTER_FILE, POSTER_LOG)
with open("cron_file", "w") as f:
f.write(SPIDER_CRON)
f.write(POSTER_CRON)
log("cron file has been made!")
os.system("crontab cron_file")