python - 在两个日期之间执行函数 X 次,我该怎么做?
问题描述
如果我能够在两个日期之间的(用户指定的)时间内执行一个函数,我会怎么做?
我在正确的轨道上吗?
from datetime import date, datetime
from upload import *
current_time = datetime.utcnow()
start_time = datetime.time.hour(17)
end_time = datetime.time.hour(20)
imageposts = []
post_limit = 0
for imagepost in imageposts:
if start_time <= current_time & current.time <= end_time & post_limit <= 3:
try:
upload()
postlimit += 1
except:
print('Current time is not between times')
解决方案
尝试这个:
from datetime import datetime
from upload import *
current_time = datetime.utcnow()
year, month, day = current_time.year, current_time.month, current_time.day
start_time = datetime(year, month, day, 17)
end_time = datetime(year, month, day, 20, 59, 59)
imageposts = []
post_limit = 0
for imagepost in imageposts:
if start_time <= current.time <= end_time and post_limit <= 3:
try:
upload()
post_limit += 1
except:
print('Current time is not between times')
推荐阅读
- javascript - 无法向 algolia 添加新对象
- geometry - 使用 turfjs 和传单在 GeoJson 层中绘制 A0 到 Z....var
- scala - Scala Spark 将多列对分解成行
- javascript - 如何使下拉菜单从底部滑入并使幻灯片平滑?
- c# - 如何将文本粘贴到 PDF 文档的每一页?
- r - 你如何对 R 中的变量求和?
- c# - Selenium浏览器c#点击
- powershell - 使用 PowerShell 根据开始和结束行号参数从 CSV 文件中获取文件头和文件的一部分
- android - 当您甚至无法在日志中找到任何类路径时如何追溯 ANR?
- docker - 在 Docker 中使用 elasticsearch:无法建立新连接