old_contents: from time import time
  from datetime import datetime
  
  class ThrottlingQuota(): 
      def __init__(self, ttl, quota): 
          self._dict = {} 
          self.ttl = ttl 
          self.quota = quota 
      def add(self, user): 
          if user in self._dict: 
              q = self._dict[user] 
              if q['expires'] < time(): 
                  q['count'] = 1 
                  q['expires'] = (1 + time() // self.ttl) * self.ttl 
              else: 
                   
                  q['count'] += 1 
                  if q['count'] > self.quota: 
                      return dict(**q, quota=self.quota, exceeded=True, comment=datetime.fromtimestamp(q['expires']).isoformat()) 
          else: 
              q = self._dict[user] = {'count': 1, 'expires':  (1 + time() // self.ttl) * self.ttl 
              }  
          return dict(**q, quota=self.quota) 
  
  tq = ThrottlingQuota(20, 100)
  for i in range(100):
    tq.add(1)
  
  
  
new_contents: from time import time
  from datetime import datetime
  
  
  class ThrottlingQuota:
      def __init__(self, ttl, limit):
          self._dict = {}
          self.ttl = ttl
          self.limit = limit
  
      def consume(self, user):
          if user in self._dict:
              q = self._dict[user]
              if q["reset"] < time():
                  q["remaining"] = self.limit
                  q["reset"] = (1 + time() // self.ttl) * self.ttl
              else:
                  q["remaining"] -= 1
                  if q["remaining"] < 0:
                      return dict(
                          limit=self.limit,
                          remaining=0,
                          reset=int(q["reset"] - time()),
                          user=user,
                          comment=datetime.fromtimestamp(q["reset"]).isoformat()
                      )
          else:
              q = self._dict[user] = {
                  "remaining": self.limit,
                  "reset": (1 + time() // self.ttl) * self.ttl,
              }
          return dict(
              limit=self.limit,
              remaining=q["remaining"],
              reset=int(q["reset"] - time()),
              user=user,
              comment=datetime.fromtimestamp(q["reset"]).isoformat()
          )
  
  
  tq = ThrottlingQuota(20, 100)
  for i in range(90):
      tq.consume(1)
  print(tq.consume(1))
  for i in range(90):
      tq.consume(1)
  print(tq.consume(1))
  
subject: fix quota manager