0
我目前正在開發一個Python項目。代碼將在特定時間刷新並獲取新記錄並更新數據庫。我想要實現的是每15分鐘或30分鐘刷新一次。下面的代碼是很好的,但只在每天上午00點提取一次新記錄。在python上設置特定的時間間隔
def check_schedule_task(self):
# update group member list at 00:00 am every morning
t = time.localtime()
if t.tm_hour == 0 and t.tm_min <= 1:
# update group member
Log.debug('update group member list everyday')
self.db.delete_table(Constant.TABLE_GROUP_LIST())
self.db.delete_table(Constant.TABLE_GROUP_USER_LIST())
self.db.create_table(Constant.TABLE_GROUP_LIST(), Constant.TABLE_GROUP_LIST_COL)
self.db.create_table(Constant.TABLE_GROUP_USER_LIST(), Constant.TABLE_GROUP_USER_LIST_COL)
self.wechat.fetch_group_contacts()
我試過以下,但它的刷新每一秒
def check_schedule_task(self):
# update group member list at 00:00 am every morning
t = time.localtime()
if t.tm_min == 15 or 30 or 45 or 00:
# update group member
Log.debug('update group member list everyday')
self.db.delete_table(Constant.TABLE_GROUP_LIST())
self.db.delete_table(Constant.TABLE_GROUP_USER_LIST())
self.db.create_table(Constant.TABLE_GROUP_LIST(), Constant.TABLE_GROUP_LIST_COL)
self.db.create_table(Constant.TABLE_GROUP_USER_LIST(), Constant.TABLE_GROUP_USER_LIST_COL)
self.wechat.fetch_group_contacts()
您還應該顯示'if var == 15或var == 30或var == 45或var == 00'方法。 – 3D1T0R
如果t.tm_min在(15,30,45,00):>這個很好用,謝謝兄弟 –