code: def sleep_if_necessary(cls, user, token, endpoint='search', msg=''):
          
          my_kw = {'auth': (user, token)} if user else {}
          info = requests.get('https://api.github.com/rate_limit', **my_kw)
          info_dict = info.json()
          remaining = info_dict['resources'][endpoint]['remaining']
          logging.debug('Search remaining on github is at %s', remaining)
  
          if remaining <= 5:
              sleep_time = 120
          else:
              sleep_time = 0
          if sleep_time:
              logging.warning('Sleep %i since github requests remaining  = %i%s',
                              sleep_time, remaining, msg)
              time.sleep(sleep_time)
              return True
  
          return False
docs: Sleep a little if hit github recently to honor rate limit.