diff --git a/pnut-bridge.py b/pnut-bridge.py index 5865f5d..025de43 100644 --- a/pnut-bridge.py +++ b/pnut-bridge.py @@ -17,6 +17,7 @@ class ChannelMonitor(threading.Thread): def __init__(self): threading.Thread.__init__(self) + self.pnut = Pnut(app.config['MATRIX_PNUT_TOKEN']) self.matrix_api_url = app.config['MATRIX_HOST'] + '/_matrix/client/r0' self.matrix_api_token = app.config['MATRIX_AS_TOKEN'] self.txId = 0 @@ -108,9 +109,8 @@ class ChannelMonitor(threading.Thread): def poll_channel(self, room): try: - r = Pnut(app.config['MATRIX_PNUT_TOKEN']).get_channel_stream(room.pnut_chan, room.pnut_since) - if r.headers['X-RateLimit-Remaining'] < 40: - print(r.headers['X-RateLimit-Remaining'], r.headers['X-RateLimit-Reset']) + r = self.pnut.get_channel_stream(room.pnut_chan, room.pnut_since) + print(r.headers['X-RateLimit-Remaining'], r.headers['X-RateLimit-Reset']) except requests.exceptions.ConnectionError: logging.info('*** Problem connecting to pnut.io! Waiting to retry. ***') time.sleep(30) @@ -189,8 +189,8 @@ class ChannelMonitor(threading.Thread): rooms = MatrixRoom2.query.all() for r in rooms: self.poll_channel(r) - time.sleep(1) - time.sleep(1.5) + time.sleep(.25) + time.sleep(3) logging.info("-- Stopping channel monitor --") if __name__ == '__main__': @@ -207,4 +207,4 @@ if __name__ == '__main__': app.run(port=config['LISTEN_PORT']) _shutdown.set() - logging.info("-- Shutdown in progress --") \ No newline at end of file + logging.info("-- Shutdown in progress --")