def dateRange(start, end, step=1, format="%Y-%m-%d"):
strptime, strftime = datetime.datetime.strptime, datetime.datetime.strftime
days = (strptime(end, format) - strptime(start, format)).days
return [strftime(strptime(start, format) + datetime.timedelta(i), format) for i in xrange(0, days, step)]
ef weekend():
try:
dayday = dateRange(st, ed)
for day in dayday:
d =day.replace('-','')
date = d
server_url = "http://www.easybots.cn/api/holiday.php?d="
vop_url_request = urllib2.Request(server_url + date)
vop_response = urllib2.urlopen(vop_url_request)
vop_data = json.loads(vop_response.read())
if vop_data[date] == '1' or vop_data[date] == '2':
dayday.remove(day)
return dayday
except:
dayday = dateRange(st, ed)
return dayday
There is such a weekend function to request some content, but some content will be missing every time it is executed. It is suspected to be a problem with the network speed. How to limit the frequency of traversal or access once in a few seconds?
After each iteration, add a sleep time
That is, your code can be adjusted to:
I found the problem. The remove operation on the original list during traversal will change the length of the list, which will lead to misalignment of the list. The final result is not the desired result