Git Product home page Git Product logo

patter's Introduction

patter

Pipe stdout directly to Mattermost.

patter demo

Install

$ pip install patter

Then set the following environment variables based on your Mattermost server's config:

MATTERMOST_TEAM_NAME
MATTERMOST_URL
MATTERMOST_USERNAME
MATTERMOST_PASSWORD
MATTERMOST_PORT

Usage

Send a message to a user.

echo "testing" | patter -u some_user

Send a message to a channel.

echo "testing" | patter -c town-square

Send a file.

patter -c town-square -f some_file.txt

Todo

  • add unit tests via pytest
  • allow message/files that are not UTF-8 to be sent
  • add option of reading from a .patter file instead of using env vars.
  • remove prints and add logging via verbose flag

Contribute

PRs accepted.

License

MIT © Christopher Hranj

Notice: This project was developed in part during my 10% time at Truveris, Inc.

patter's People

Contributors

brodan avatar kaleposhobios avatar vr2262 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

patter's Issues

After upgrade from 0.1.0 to 0.2.0 it stops working

Hi,

I have tried to upgrade it. And the following occured, notice last version worked fine.

Revenger:patter-0.1.0.dist-info cosmicsound$ pip install patter --upgrade
Collecting patter
  Downloading https://files.pythonhosted.org/packages/43/48/ffb0fed9e55970677c7e87e9787ccc2d36022ef3f424db3e59c7fccc635e/patter-0.2.0-py3-none-any.whl
Requirement already satisfied, skipping upgrade: mattermostdriver>=5.0.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from patter) (5.0.0)
Requirement already satisfied, skipping upgrade: websockets>=3.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from mattermostdriver>=5.0.0->patter) (6.0)
Requirement already satisfied, skipping upgrade: requests>=2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from mattermostdriver>=5.0.0->patter) (2.19.1)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests>=2.1->mattermostdriver>=5.0.0->patter) (2018.4.16)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests>=2.1->mattermostdriver>=5.0.0->patter) (3.0.4)
Requirement already satisfied, skipping upgrade: urllib3<1.24,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests>=2.1->mattermostdriver>=5.0.0->patter) (1.23)
Requirement already satisfied, skipping upgrade: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests>=2.1->mattermostdriver>=5.0.0->patter) (2.7)
Installing collected packages: patter
  Found existing installation: patter 0.1.0
    Uninstalling patter-0.1.0:
      Successfully uninstalled patter-0.1.0
Successfully installed patter-0.2.0
Revenger:patter-0.1.0.dist-info cosmicsound$ history | grep echo
  301  echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
  345  echo "testing" | patter -c town-square
  360  echo "testing" | patter -c town-square
  368  echo "testing" | patter -c town-square
  371  echo "testing" | patter -c town-square
  374  echo "testing" | patter -c town-square
  377  echo "testing" | patter -c town-square
  379  echo "testing" | patter -c town-square
  380  echo "testing" | patter -c town-square
  383  echo "testing" | patter -c town-square
  386  echo "testing" | patter -c town-square
  389  echo "testing" | patter -c town-square
  390  cd '/Users/cosmicsound/Documents/GitHub/patter/' && '/usr/local/bin/pythonw'  '/Users/cosmicsound/Documents/GitHub/patter/setup.py'  && echo Exit status: $? && exit 1
  391  cd '' && '/usr/local/bin/pythonw' -d -v -i -O -t  '<your script here>'  && echo Exit status: $? && exit 1
  392  cd '/Users/cosmicsound/Documents/GitHub/patter/' && '/usr/local/bin/pythonw'  '/Users/cosmicsound/Documents/GitHub/patter/setup.py'  && echo Exit status: $? && exit 1
  522  history | grep echo
Revenger:patter-0.1.0.dist-info cosmicsound$ echo "testing" | patter -c town-square
-bash: /Library/Frameworks/Python.framework/Versions/3.7/bin/patter: /Users/chranj/homebrew/opt/python/bin/python3.7: bad interpreter: No such file or directory
Revenger:patter-0.1.0.dist-info cosmicsound$ echo "testing" | patter -c town-square
-bash: /Library/Frameworks/Python.framework/Versions/3.7/bin/patter: /Users/chranj/homebrew/opt/python/bin/python3.7: bad interpreter: No such file or directory
Revenger:patter-0.1.0.dist-info cosmicsound$ 

Note that this path:

/Users/chranj/homebrew/opt/python/bin/python3.7

Become embedded in the install process somehow
I do not have such username on my mac.

Best
Cosmin

While piping errors

➜ Documents pip install patter
Collecting patter
Downloading https://files.pythonhosted.org/packages/3e/86/eea5f3b98e8c2598daaf1c8e87d5a1e2f1930b9f1301be797194d0b8680a/patter-0.1.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/vk/6d2cgfk965sc6q8mc73886_80000gn/T/pip-install-9N3esq/patter/setup.py", line 6, in
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/vk/6d2cgfk965sc6q8mc73886_80000gn/T/pip-install-9N3esq/patter/
➜ Documents pip install patter

I managed to fix this issue with pip3 install patter .

Formats allowed to be sent

tried to send an archive, what formats are supported only .txt?

Revenger:~ cosmicsound$ patter -c town-square -f Archive.zip 
Traceback (most recent call last):
  File "/usr/local/bin/patter", line 60, in <module>
    patter.send_message()
  File "/usr/local/lib/python3.7/site-packages/patter/patter.py", line 83, in send_message
    attached_file_id = self._attach_file(self.filename, channel_id)
  File "/usr/local/lib/python3.7/site-packages/patter/patter.py", line 193, in _attach_file
    files={"files": (filename, open(filename))}
  File "/usr/local/lib/python3.7/site-packages/mattermostdriver/endpoints/files.py", line 11, in upload_file
    files=files
  File "/usr/local/lib/python3.7/site-packages/mattermostdriver/client.py", line 169, in post
    return self.make_request('post', endpoint, options=options, params=params, data=data, files=files).json()
  File "/usr/local/lib/python3.7/site-packages/mattermostdriver/client.py", line 137, in make_request
    files=files
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 498, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 441, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 312, in prepare
    self.prepare_body(data, files, json)
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 500, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 159, in _encode_files
    fdata = fp.read()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 11: invalid start byte
Revenger:~ cosmicsound$ patter -c town-square -f ~/.ssh/config 
Revenger:~ cosmicsound$ 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.