GithubHelp home page GithubHelp logo

syabruk / pync Goto Github PK

View Code? Open in Web Editor NEW
354.0 15.0 35.0 475 KB

Python wrapper for Mac OS 10.8 Notification Center

Home Page: https://pypi.org/project/pync

License: Other

Python 100.00%
pync notification-center python apple macos notifications pypi

pync's People

Contributors

andysim3d avatar daxeel avatar duynguyenhoang avatar joshuakarjala avatar jvhellemond avatar kyrias avatar maizy avatar mangecoeur avatar maxkrivich avatar megalithic avatar syabruk avatar tingping avatar vaidik 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pync's Issues

FileNotFoundError during install of 2.0.0

$ pip install pync
Collecting pync
  Using cached pync-2.0.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/h1/2b6gts3x37zcnj5khyv8y5180000gn/T/pip-build-8sa_tyyb/pync/setup.py", line 10, in <module>
        file_contents.append(open(path).read())
    FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/h1/2b6gts3x37zcnj5khyv8y5180000gn/T/pip-build-8sa_tyyb/pync/README.md'

Support for PyInstaller bundle?

Hi SeTeM! First of all thanks for providing this python binding of Terminal-Notifier.
I found it failed within a PyInstaller bundled .app folder. And as I could not ask every end user to install terminal-notifier, I decide to pack the vendor folder into the .app bundle. But that leaded to another problem: the path of vendor folder was coded as the same level of TerminalNotifier.py file, yet TerminalNotifier.py would be bundled into a .pyz archive file.
If this could be solved I'd be very much appreciated.

Issues with unicode/ASCII encoding/decoding of messages when receiving notifications from weechat

Describe the bug

On macOS 10.13.6 (high sierra), using the latest pync installed via github, the latest version of weechat, the latest notification_center.py weechat plugin installed via /script command in weechat, and latest terminal-notifier (using either the ruby gem or the homebrew formula).

I get the following error:

11:15 python: stdout/stderr (notification_center): Traceback (most recent call last):
11:15 python: stdout/stderr (notification_center):   File "/Users/me/.dotfiles/private/weechat/python/autoload/notification_center.py", line 63, in notify
11:15 python: stdout/stderr (notification_center):     Notifier.notify('From %s' % prefix, title='Private Message', sound=sound, appIcon=WEECHAT_ICON, activate=activate_bundle_id)
11:15 python: stdout/stderr (notification_center):   File "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pync/TerminalNotifier.py", line 73, in notify
11:15 python: stdout/stderr (notification_center):     message = message.encode('utf-8')
11:15 python: stdout/stderr (notification_center): UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 5: ordinal not in range(128)
11:15 ⚠ python: error in function "notify"

Desktop (please complete the following information):

  • OS: macOS
  • Version 10.13.6
  • kitty: 0.12.3
  • tmux: 2.7
  • zsh: 5.6.2
  • weechat: 2.3
  • pync: 2.0.4
  • notification_center.py: 1.3.0
  • terminal-notifier: 2.0.0

To Reproduce

Steps to reproduce the behavior:

  1. Install weechat, pync, terminal-notifier, and the notification_center.py plugin versions shown above (those are all the latest versions as of the writing of this issue).
  2. Have someone @ you, or DM you, or what not within IRC, whatever bitlbee or other server source you might be using.
  3. Without fail, the above error occurs.

Expected behavior

I would expect the notification to popup, I can call terminal-notifier directly from a term prompt and it raises a notification (using the basic example on their repo: echo 'Piped Message Data!' | terminal-notifier -sound default.

Additional context

I tried fiddling with the notification_center.py plugin to see if i can add more logging or more encoding/decoding for unicode and/or ascii or other file format types (trying the things others on stackoverflow and other github repos have suggested to work around this), but to no avail. I still end up with an error from pync.

What's interesting is if i just output directly to a weechat buffer (like the core buffer), the message sent that should be getting passed, ultimately to pync/terminal-notifier, the message text looks just fine, but for some reason pync just doesn't like it at all.

Failure on High Sierra

$ python
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> from pync import Notifier
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.13-intel/egg/pync/__init__.py", line 3, in <module>
  File "build/bdist.macosx-10.13-intel/egg/pync/TerminalNotifier.py", line 130, in <module>
  File "build/bdist.macosx-10.13-intel/egg/pync/TerminalNotifier.py", line 37, in __init__
Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ and file a bug.```

is pync compatible with OSX El Capitan?

I'm having trouble getting pync to install. Is this some sort of SIP issue with El Capitan, or am I just doing something dumb?

sudo -H pip install pync
Collecting pync
  Using cached pync-1.6.1.tar.gz
Collecting python-dateutil>=2.0 (from pync)
  Using cached python_dateutil-2.5.3-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil>=2.0->pync)
  Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, pync
  Found existing installation: six 1.4.1
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 736, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 742, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-wlYSeB-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

Cannot use UTF-8 strings

i just encountered an issue when passing a translated string containing non-ascii characters.

Traceback (most recent call last):
  [...]
  File "/Users/user/Desktop/MyApp/virt/lib/python2.7/site-packages/pync/TerminalNotifier.py", line 74, in notify
    return self.execute(args)
  File "/Users/user/Desktop/MyApp/virt/lib/python2.7/site-packages/pync/TerminalNotifier.py", line 77, in execute
    args = [str(arg) for arg in args]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 39: ordinal not in range(128)

Using unicode(arg) instead of str(arg) should fix this.

installing pync on max osx 10.8.5

from pync import Notifier
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.macosx-10.8-intel/egg/pync/init.py", line 3, in
File "build/bdist.macosx-10.8-intel/egg/pync/TerminalNotifier.py", line 99, in
File "build/bdist.macosx-10.8-intel/egg/pync/TerminalNotifier.py", line 27, in init
Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ and file a bug.

Error occured during installation process.
git clone git://github.com/SeTeM/pync.git
cd pync
python setup.py install

Using the notify function bug

Calling notify() is not working.

Here is code,

import pync
pync.notify('Hello World')

Error :

AttributeError: 'module' object has no attribute 'notify'

Exception

The python file (pync_test.py) has the example code from github

akhils-mbp15:~ akhils$ python ~/Documents/py/pync_test.py

Traceback (most recent call last):
File "/Users/akhils/Documents/py/pync_test.py", line 1, in
from pync import Notifier
File "build/bdist.macosx-10.8-intel/egg/pync/init.py", line 3, in
File "build/bdist.macosx-10.8-intel/egg/pync/TerminalNotifier.py", line 99, in
File "build/bdist.macosx-10.8-intel/egg/pync/TerminalNotifier.py", line 27, in init
Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ and file a bug.

Suggestion: functional api

Just a thought

from pync import Notifier
Notifier.notify(...)

Seems a bit redundant. Why not have an api like

import pync
pync.notify(...)

Which internally would just do

def notify(*args, **kwargs):
    Notifier.notify(*args, **kwargs)

Unable to get it working on osx 10.9.3

After installing I try to run it in python terminal:

Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

from pync import Notifier
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/pync/init.py", line 3, in
from .TerminalNotifier import Notifier
File "/Library/Python/2.7/site-packages/pync/TerminalNotifier.py", line 116, in
Notifier = TerminalNotifier()
File "/Library/Python/2.7/site-packages/pync/TerminalNotifier.py", line 29, in init
raise Exception("pync was not properly installed. Head over to https://github.com/SeTeM/pync/"
Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ and file a bug.

remove_notifications and list_notifications are not promoted to package level

Describe the bug
can not call
pync.remove_notifications(os.getpid()) and pync.list_notifications(os.getpid()) directly because those two function are not promote to package level.

To Reproduce
Steps to reproduce the behavior:
In any python file, call pync.remove_notifications(os.getpid()) or
pync.list_notifications(os.getpid()), it will raise execption module 'pync' has no attribute 'remove_notifications'

Expected behavior
As document said, it supports pync.remove_notifications and pync.list_notification

Desktop (please complete the following information):

  • OS: MacOS
  • Version: 10.14.4

Additional context
Add any other context about the problem here.

Installation Issue on Mavericks

Tried importing from pync after installing, got this error:

>>> from pync import Notifyer as nc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.9-intel/egg/pync/__init__.py", line 3, in <module>
  File "build/bdist.macosx-10.9-intel/egg/pync/TerminalNotifier.py", line 99, in <module>
  File "build/bdist.macosx-10.9-intel/egg/pync/TerminalNotifier.py", line 27, in __init__
Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ and file a bug.

appIcon

How can i change an icon?

Don't work after update to 10.9

No notifications, no exceptions

In [1]: from pync import Notifier

In [2]: Notifier.notify('Hello World')

In [3]: Notifier.notify('Hello World', execute='say "OMG"')

In [4]: Notifier.list(os.getpid())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/tug/Work/playground/Python/env/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 Notifier.list(os.getpid())

/Users/tug/Work/playground/Python/env/lib/python2.7/site-packages/pync/TerminalNotifier.pyc in list(self, group)
     99         If no information is available this will return [].
    100         """
--> 101         output = self.execute(["-list", group]).communicate()[0]
    102         res = list()
    103         for line in output.splitlines()[1:]:

/Users/tug/Work/playground/Python/env/lib/python2.7/site-packages/pync/TerminalNotifier.pyc in execute(self, verbose)
     75 
     76     def execute(self, verbose):
---> 77         output = subprocess.Popen([self.bin_path,] + verbose, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     78         if output.returncode:
     79             raise Exception("Some error during subprocess call.")

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    709                                 p2cread, p2cwrite,
    710                                 c2pread, c2pwrite,
--> 711                                 errread, errwrite)
    712         except Exception:
    713             # Preserve original exception in case os.close raises.

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1306                         raise
   1307                 child_exception = pickle.loads(data)
-> 1308                 raise child_exception
   1309 
   1310 

TypeError: execv() arg 2 must contain only strings

pync was not properly installed

Hi
I have an "Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ and file a bug." during compiling program with py2app. I've installed an actual version from github, but it didn't work. Also I found here a bug issue #17, but I dont even have this files on package directories.
That's my first topic, so I'll also put my code there, may be it will be useful.

import clipboard
import pync
import time

with open('таблицапринтов.txt') as f:
    content = f.readlines()
content = [x.strip() for x in content]
keydict = {}
for i in range(len(content)):
    k=content[i]
    test = content[i].split()
    keydict[test[0]] = test[len(test)-1]
check=0
while True:
    time.sleep(1.5)
    text = clipboard.paste()
    if not text==check:
     if text in keydict.keys():
        pync.notify('Ссылка в буфере', appIcon='right.png', title='PrintSearch')
        clipboard.copy(keydict[text])
        check=text
     elif not text in keydict.values():
        pync.notify('Ссылки нет в базе', appIcon='wrong.png', title='PrintSearch')
        check=text
  • default setup.py py2app file
    Pls help

list() method raises AttributeError

When trying to get a list of notifications sent, we get an AttributeError

>>> from pync import Notifier
>>> Notifier.list()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pync/TerminalNotifier.py", line 107, in list
    output = self.execute(["-list", group]).communicate()[0]
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pync/TerminalNotifier.py", line 79, in execute
    if self.wait:
AttributeError: 'TerminalNotifier' object has no attribute 'wait'```

pync.notify not working in python scripts used by launchd

Describe the bug
pync.notify doesn't work in python scripts used by launchd, but works when the python script is directly executed.

So I have python script in /Users/tscp/testdir/test-pync/test_pync.py:

#!/usr/local/bin/python3.8
import pync
import sys

print('before')
pync_imported = 'pync' in sys.modules
print(f'pync is imported: {pync_imported}')
pync.notify('test pync')
print('after')

It works as expected (a notification is shown) when run with ./test_pync.py, but doesn't run in my launchd job /Users/tscp/Library/LaunchAgents/test_pync.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>local.job</string>
	<key>Program</key>
	<string>/Users/tscp/testdir/test-pync/test_pync.py</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/tmp/local.job.stderr</string>
	<key>StandardOutPath</key>
	<string>/tmp/local.job.stdout</string>
</dict>
</plist>

This is the content of /tmp/local.job.stdout after the job is loaded:

before
pync is imported: True
after

The script seemed to run successfully but the notification was not shown.

To Reproduce
Steps to reproduce the behavior:

brew install [email protected] && python3.8 -m pip install pync

mkdir -p ~/testdir/test-pync
# copy test_pync.py above to ~/testdir/test-pync/test_pync.py
chmod 755 ~/testdir/test-pync/test_pync.py

# copy test_pync.plist above to ~/Library/LaunchAgents/test_pync.plist
# and substitute `/Users/tscp` in the plist file with your home path

launchctl load  ~/Library/LaunchAgents/test_pync.plist
cat /tmp/local.job.stdout

Expected behavior
A notification like this is shown when the job is loaded and run:
image

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Version: tested on both 10.15.6 / 10.15.7.

Additional context
Add any other context about the problem here.

Installation error with Python3

Tried a few different methods, but every time I try to install the package with Python 3, I get the following error:

pip3 install pync
Collecting pync
  Using cached pync-1.6.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/64/vnv3jxhs47gbzbw3wcjf0hyw0000gn/T/pip-build-152ozf45/pync/setup.py", line 10, in <module>
        file_contents.append(open(path).read())
      File "/Users/romanpeters/Projects/Python/Scripts/venv/bin/../lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 589: ordinal not in range(128)
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/64/vnv3jxhs47gbzbw3wcjf0hyw0000gn/T/pip-build-152ozf45/pync/

Python 2 still seems to work.

Nicer way of depending on Terminal Notifier

I see that pync tries to download Terminal Notifier, which is a different non-python project, after installation. That creates problems for people who would like to use pync globally and not in a virtualenv because at the time of the first run, the application must be running with root's rights.

A nicer way of installing TermincalNotifier would be to have TerminalNotifier inside this repo and packaging it along with pync.

I'll try to look into this since I am interested in using this project.

pync was not properly installed on Ubuntu Linux 3.2.0

pync was imported as part of a craigslist scrapper made by arlando. After cloning his repo and getting the necessary libraries from pip, I got the following traceback:

Traceback (most recent call last):
File "scraper.py", line 22, in
from pync import Notifier
File "/usr/local/lib/python2.7/dist-packages/pync/init.py", line 3, in
from .TerminalNotifier import Notifier
File "/usr/local/lib/python2.7/dist-packages/pync/TerminalNotifier.py", line 116, in
Notifier = TerminalNotifier()
File "/usr/local/lib/python2.7/dist-packages/pync/TerminalNotifier.py", line 29, in init
raise Exception("pync was not properly installed. Head over to https://github.com/SeTeM/pync/"
Exception: pync was not properly installed. Head over to https://github.com/SeTeM/pync/ >and file a bug.

Are there any logs being saved somewhere else you'd need to figure this out?

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.