Created
August 22, 2012 09:20
-
-
Save KitWallace/3423989 to your computer and use it in GitHub Desktop.
Part 2 - cache invalidation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
... | |
def __init__(self,id,url,rate) : | |
self.url = url | |
self.id = id | |
self.ts = 0 | |
self.rate = int(rate) | |
self.refresh() | |
def refresh(self) : | |
if time.time() - self.ts > self.rate : | |
try : | |
page = urllib.urlopen(self.url) | |
report = page.readline() | |
data = report.split(" ") | |
self.wind_speed = data[1] | |
self.gust_speed = data[2] | |
... | |
self.ts = time.time() | |
except : | |
pass | |
else : | |
pass | |
def get_baro(self) : | |
self.refresh() | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment