import urllib2
import datetime
#Test client behavior:
#1. Start time at the 2nd feed fetch.
#2. Fetch feed.
#3. Increment timer
#4. Fetch next feed using IMS=last feed time, and client-time=timer
class mydatetime(datetime.datetime):
def __str__(self):
return "%.2d-%.2d-%.2d_%.2d:%.2d:%.2d"%(self.year,self.month,self.day,self.hour,self.minute,self.second)
def cast(self,dt):
return self.replace(year=dt.year, month=dt.month, day=dt.day, hour=dt.hour, minute=dt.minute, second=dt.second)
timer=mydatetime(2006,12,31,14,30,00)
end_time=mydatetime(2007,1,2,10,30,0)
last_time=""
while timer < end_time:
req=urllib2.Request("http://localhost:8000/Slashdot",headers={"If-Modified-Since":last_time,"Client-Time":timer})
try:
response=urllib2.urlopen(req)
print "Got new"
last_time=timer
except urllib2.HTTPError, e:
print "Error: ",e,last_time, timer
dtimer=timer+datetime.timedelta(0,0,0,0,10)
timer=timer.cast(dtimer)