def logging_cleanup(self):
     EXPIRATION_WINDOW = timedelta(seconds=60*60*24) # 1 hour
     query = OAuthStatusCodes.all().filter(
         'date <', datetime.now() - EXPIRATION_WINDOW
         )
     count = query.count(CLEANUP_BATCH_SIZE)
     db.delete(query.fetch(CLEANUP_BATCH_SIZE))
     return "Cleaned %i entries" % count
 def logging(self, method, api_method, status_code, **extra_params):
     oauth_status_codes = OAuthStatusCodes()
     oauth_status_codes.method = method
     oauth_status_codes.api_method = api_method
     oauth_status_codes.status_code = status_code
     if extra_params is not None:
         param_str = ''
         for key, item in extra_params.items():
             param_str += '%s : %s,' % (key, unicode(item, 'utf-8'))
             if key == 'status':
                 oauth_status_codes.tweet = unicode(item, 'utf-8')
         oauth_status_codes.extra_params = param_str
     oauth_status_codes.oauth_access_token_key = self.token.key()
     oauth_status_codes.put()
 def cleanup(self):
     query = OAuthRequestToken.all().filter(
         'created <', datetime.now() - EXPIRATION_WINDOW
         )
     token_count = query.count(CLEANUP_BATCH_SIZE)
     db.delete(query.fetch(CLEANUP_BATCH_SIZE))
     
     EXPIRATION_STATUS_CODES = timedelta(seconds=60*60*24*3) # 3 days
     query = OAuthStatusCodes.all().filter(
         'date <', datetime.now() - EXPIRATION_STATUS_CODES
         )
     codes_count = query.count(CLEANUP_BATCH_SIZE)
     db.delete(query.fetch(CLEANUP_BATCH_SIZE))
     return "Cleaned Token:%i Codes:%i entries" % (token_count, codes_count)