Last active
July 26, 2019 06:13
-
-
Save zingi/5f6ef38d175cd486de028d081df66a3f to your computer and use it in GitHub Desktop.
Set Mattermost Status to online on Mouse move
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynput import mouse | |
| from mattermostdriver import Driver | |
| import time | |
| import datetime | |
| ''' | |
| Since the Mattermost desktop client, only sets the status to _online_ | |
| if you interact with the client window: this script was created, | |
| to set the status to online even if you only move the mouse cursor. | |
| To exit the running script press Enter. | |
| Don't just do ctrl+C, otherwise a open session will remain linked to your Mattermost account. | |
| Before starting the script, install requried packages: | |
| pip install pynput | |
| pip install mattermostdriver | |
| Hints: | |
| - mattermostdriver requires Python 3.4 or later | |
| - pynput needs some special permissions on macOS: | |
| https://pynput.readthedocs.io/en/latest/limitations.html | |
| ''' | |
| # fill in your login data | |
| login_id = 'myMattermostUsername' | |
| password = 'myMattermostPassword' | |
| # fill in your server information | |
| url = 'mattermost.example.com' | |
| scheme = 'https' | |
| port = 443 | |
| ################################################################################# | |
| connection = None # connection to mattermost | |
| user_id = 'me' # id of current mattermost user | |
| wait = 10 # request throttle | |
| ts = 0 # timestamp (seconds since epoch) | |
| # callback method for mouse move | |
| def on_move(x, y): | |
| global ts | |
| # in order not to spam requests, send a request only every [wait] seconds | |
| if(time.time() > ts + wait): | |
| ts = time.time() | |
| if connection != None: | |
| connection.status.update_user_status(user_id, options={ | |
| 'user_id': user_id, | |
| 'status': 'online' | |
| }) | |
| print('push online @ {0}'.format(datetime.datetime.now()), end='\r') | |
| if __name__ == "__main__": | |
| # create a mattermost session | |
| connection = Driver({ | |
| 'url': url, | |
| 'login_id': login_id, | |
| 'password': password, | |
| 'scheme': scheme, | |
| 'port': port | |
| }) | |
| connection.login() | |
| # fetch the user_id | |
| me = connection.users.get_user('me') | |
| user_id = me['id'] | |
| # Collect events until released | |
| listener = mouse.Listener(on_move=on_move) | |
| listener.start() | |
| # block termination until enter pressed | |
| input('[to exit press enter]\n') | |
| listener.stop() | |
| connection.logout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment