Example #1
0
 def GET(self):
     kvdb = sae.kvdb.KVClient()
     if hasattr(self, 'update_info'):
         import time
         time.sleep(8)
         raise web.found('/howareyou')
         this_quote = self.update_info
     else:
         try:
             today_quotes = kvdb.get_by_prefix(const.QUOTE_PREFIX)
         except:
             today_quotes = Nothing() #else None is not iterable
         today_quote_probs = 0 if not today_quotes else 3.5
         try:
             weather = kvdb.get('weather')
         except:
             weather = Nothing() #else None is not iterable
         weather_probs = 0 if not weather else 2
         this_quote = Howareyou.weighted_pick([(quotes, 1), ([q[1] for q in today_quotes], today_quote_probs), ([weather], weather_probs)])
     # this_quote = random.choice(quotes)
     # if web.input().get('from') == 'poly':
     # this_quote = '''<p><b>松江天气(<a href='http://www.weather.com.cn/weather/101020900.shtml'>11/21 10:00</a>)</b></p>小雨转小到中雨,东风3-4级,12℃~15℃,当前气温8°。'''
     web.header('Content-Type', 'text/html; charset=utf-8', unique=True)
     web.header('Content-Length', len(this_quote), unique=True)
     web.header('X-How-Are-You', 'fine', unique=True)
     return this_quote
    def GET(self):
        kvdb = sae.kvdb.KVClient()
        expired = []

        if kvdb.get_by_prefix(const.QUOTE_PREFIX):
	        items = kvdb.get_by_prefix(const.QUOTE_PREFIX)
	        expired = filter(lambda item: float(item[0].rpartition('_')[-1])<=time.time(), items)
        if kvdb.get('weather'):
        	today = datetime.date.today().strftime('%m/%d')
        	try:
	        	update_day = re.search(r'>(\d{1,2}/\d{1,2})', kvdb.get('weather')).group(1)
	        except:
	        	update_day = '12/31'
	        if update_day<today:
	        	expired.append(('weather', None))
        map(lambda item: kvdb.delete(item[0]), expired)
        return expired