本文整理汇总了Python中schedule.Schedule.get方法的典型用法代码示例。如果您正苦于以下问题:Python Schedule.get方法的具体用法?Python Schedule.get怎么用?Python Schedule.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schedule.Schedule
的用法示例。
在下文中一共展示了Schedule.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from schedule import Schedule [as 别名]
# 或者: from schedule.Schedule import get [as 别名]
def get(self, verb="hosed", isodate=None):
if not isodate:
isodate = attnow().date().isoformat()
sched = Schedule.get()
e = sched.get_next_here_event(isodate)
logging.info("for isodate %s, isodatetime %s, next home event is %s" % (
isodate, attnow(), str(e)))
is_home = e and e['date'] == isodate
message = sched_message(isodate)
self.response.write(
template.render('templates/8ball.w2', {
'verb': verb,
'is_home': is_home,
'today': message[0],
'tomorrow': message[1]
}))
示例2: sched_message
# 需要导入模块: from schedule import Schedule [as 别名]
# 或者: from schedule.Schedule import get [as 别名]
def sched_message(isodate=None):
"""
return an informative message about today's event,
as a list of strings (one per line)
"""
if not isodate:
isodate = attnow().date().isoformat()
sched = Schedule.get()
e = sched.get_next_here_event(isodate)
if not e:
return ['No more home games!', "(...until next year...)"]
elif e['date'] != isodate:
return ['No home game today!',
'All quiet until %s, when Giants play %s at %s' % (
e['day'], e['them'], e['time'])]
else:
quiet = sched.get_next_non_here_datetime(isodate)
return ['Giants play %s at %s\n' % (e['them'], e['time']),
"No peace and quiet until %s" % quiet.strftime("%A, %b %d")]
示例3: TestScheduleClass
# 需要导入模块: from schedule import Schedule [as 别名]
# 或者: from schedule.Schedule import get [as 别名]
class TestScheduleClass(unittest.TestCase):
def setUp(self):
self.schedule = Schedule()
self.schedule.insert({
"enable": 1,
"alias": "reboot",
"command": "uptime && reboot",
"schedule": "0 0 * * *",
"executer": True
})
# self.reboot = Reboot(connection=Mockup())
def tearDown(self):
self.schedule = None
cron = CronTab(user=True)
cron.remove_all()
cron.write()
def test_insert(self):
'''Insert a job, It should insert a job and return it with id'''
result = self.schedule.insert({
"enable": 1,
"alias": "reboot",
"command": "uptime && test_insert",
"schedule": "0 0 * * *",
"executer": True
})
self.assertDictEqual({
"id": 2,
"enable": 1,
"alias": "reboot",
"command": "uptime && test_insert",
"schedule": "0 0 * * *",
"executer": True,
"comment": "sanji_schedule_2"
}, result)
jobs = []
cron = CronTab(user=True)
for job in cron.find_comment("sanji_schedule_2"):
jobs.append(job)
self.assertEqual(len(jobs), 1)
def test_update(self):
'''Update a job, It should update a job and return it'''
added = self.schedule.get()[0]
result = self.schedule.update({
"id": added["id"],
"enable": 1,
"alias": "uptime",
"command": "uptime && test_update",
"schedule": "1 1 1 * *",
"executer": True
})
self.assertNotEqual(result, None)
self.assertDictEqual({
"id": added["id"],
"enable": 1,
"alias": "uptime",
"command": "uptime && test_update",
"schedule": "1 1 1 * *",
"executer": True,
"comment": added["comment"]
}, result)
jobs = []
cron = CronTab(user=True)
for job in cron.find_comment(result["comment"]):
jobs.append(job)
self.assertEqual(job.slices, result["schedule"])
self.assertEqual(job.command, result["command"])
self.assertEqual(len(jobs), 1)
def test_delete(self):
'''Delete a job,
It should delete a job by id and return effected count'''
added = self.schedule.get()[0]
result = self.schedule.delete(added["id"])
self.assertEqual(result, 1)
result = self.schedule.get()
self.assertEqual(len(result), 0)
def test_get_all(self):
'''Get all jobs,
It should return all jobs'''
self.schedule.insert({
"enable": 1,
"alias": "1",
"command": "uptime && test_get_all",
"schedule": "0 0 * * *",
"executer": True
})
self.schedule.insert({
"enable": 1,
"alias": "1",
#.........这里部分代码省略.........