Example #1
0
 def init_2nd_step(self, verifier_num):
     info = user.get_app('sina', self.email)
     auth = OAuthHandler(APP_KEY, APP_SECRET)
     auth.set_request_token(info.get('request_token'), info.get('request_secret'))
     access = auth.get_access_token(verifier_num)
     user.update_app('sina', self.email, access_token=access.key, access_secret=access.secret)
     return True
Example #2
0
 def init_1st_step(self):
     auth = OAuthHandler(APP_KEY, APP_SECRET, '')
     auth_url = auth.get_authorization_url()
     user.update_app('sina', self.email, request_token=auth.request_token.key,
             request_secret=auth.request_token.secret)
     log.debug(repr(user.get(self.email)))
     return auth_url
Example #3
0
 def switch(self, sig, city=None):
     if sig == 'on':
         user.update_app('weather', self.email, city=city)
         return 'Turn on succed'
     elif sig == 'off':
         user.delete_app('weather', self.email)
         return 'Turn off succed'
     else:
         return "unknown option [%s]" % sig
Example #4
0
 def forecast(self):
     info = user.get_app('weather', self.email)
     if not info:
         return
     recently_send = info.get('recently_send')
     log.debug('recently send: %s' % str(recently_send))
     if recently_send and type(recently_send) in (str, unicode):
         r = time.strptime(recently_send, '%Y-%m-%d')
         recently_send = datetime.date(r.tm_year, r.tm_mon, r.tm_mday)
     if recently_send == datetime.date.today():
         return
     city = info.get('city')
     forecast = self._get_weather(city)
     result = ''
     if not forecast:
         return result
     for f in forecast:
         result += u'%(day_of_week)s: High[%(high)s], Low[%(low)s], Condition[%(condition)s]\n' % f
     user.update_app('weather', self.email, recently_send=datetime.date.today())
     return result