|
@ -6,13 +6,15 @@ class WebPage: |
|
|
|
|
|
|
|
|
def __init__(self, url): |
|
|
def __init__(self, url): |
|
|
self.url = url |
|
|
self.url = url |
|
|
|
|
|
self.an_old_time = 0 |
|
|
self._content = None |
|
|
self._content = None |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def content(self): |
|
|
def content(self): |
|
|
now = time.time() |
|
|
now = time.time() |
|
|
if not self._content: |
|
|
|
|
|
|
|
|
if not self._content or (now - self.an_old_time > 10): |
|
|
|
|
|
self.an_old_time = now |
|
|
print("Retrieving new page...") |
|
|
print("Retrieving new page...") |
|
|
self._content = urlopen(self.url).read() |
|
|
self._content = urlopen(self.url).read() |
|
|
print("Got page in {} seconds".format(time.time() - now)) |
|
|
print("Got page in {} seconds".format(time.time() - now)) |
|
|
return self._content |
|
|
|
|
|
|
|
|
return self._content |