- # Open connection
- if self.api.secure:
- conn = httplib.HTTPSConnection(self.host, timeout=self.api.timeout)
- else:
- conn = httplib.HTTPConnection(self.host, timeout=self.api.timeout)
+ # handle running out of api calls
+ if self.wait_on_rate_limit:
+ if self._reset_time is not None:
+ if self._remaining_calls is not None:
+ if self._remaining_calls < 1:
+ sleep_time = self._reset_time - int(time.time())
+ if sleep_time > 0:
+ if self.wait_on_rate_limit_notify:
+ print("Rate limit reached. Sleeping for:", sleep_time)
+ time.sleep(sleep_time + 5) # sleep for few extra sec
+
+ # if self.wait_on_rate_limit and self._reset_time is not None and \
+ # self._remaining_calls is not None and self._remaining_calls < 1:
+ # sleep_time = self._reset_time - int(time.time())
+ # if sleep_time > 0:
+ # if self.wait_on_rate_limit_notify:
+ # print("Rate limit reached. Sleeping for: " + str(sleep_time))
+ # time.sleep(sleep_time + 5) # sleep for few extra sec