本文整理汇总了Python中gntp.notifier.GrowlNotifier.notify方法的典型用法代码示例。如果您正苦于以下问题:Python GrowlNotifier.notify方法的具体用法?Python GrowlNotifier.notify怎么用?Python GrowlNotifier.notify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gntp.notifier.GrowlNotifier
的用法示例。
在下文中一共展示了GrowlNotifier.notify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestHash
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
class TestHash(unittest.TestCase):
def setUp(self):
self.growl = GrowlNotifier("GNTP unittest", ["Testing"])
self.growl.register()
def test_lines(self):
for priority in [2, 1, 0, -1, -2]:
msg = "Priority %s" % priority
self.growl.notify("Testing", msg, msg, priority=priority)
示例2: Notifier
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
class Notifier(object):
def __init__(self, app_name="autocheck"):
self.growl = GrowlNotifier(
applicationName=app_name, notifications=["New Message"], defaultNotifications=["New Message"]
)
self.growl.register()
def notify(self, title, description, kind="pass", sticky=False):
icon = open(join(dirname(__file__), "images", kind + ".png"), "rb").read()
self.growl.notify(noteType="New Message", title=title, description=description, icon=icon, sticky=sticky)
示例3: TestHash
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
class TestHash(unittest.TestCase):
def setUp(self):
self.growl = GrowlNotifier('GNTP unittest', ['Testing'])
self.growl.register()
self.dir = os.path.dirname(__file__)
self.file = os.path.join(self.dir, 'test_lines.txt')
def test_lines(self):
for line in open(self.file):
self.growl.notify('Testing', 'Line', line)
示例4: bark
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
def bark(message, host, password):
growl = GrowlNotifier(
applicationName = NAME,
notifications = [NOTIFIER],
defaultNotifications = [NOTIFIER],
hostname = host,
port = '23053',
password = password
)
growl.register()
growl.notify(
noteType = NOTIFIER,
title = TITLE,
description = message,
icon = ICON_URL,
sticky = False,
priority = 1,
)
示例5: test_client
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
def test_client(config, options):
logging.basicConfig(level=options.verbose)
notifier = GrowlNotifier(
hostname=config.get('regrowl.server', 'hostname', '127.0.0.1'),
port=config.getint('regrowl.server', 'port'),
password=config.get('regrowl.server', 'password'),
notifications=['Test']
)
if options.test in ['registration', 'all']:
notifier.register()
if options.test in ['notification', 'all']:
notifier.notify(
noteType='Test',
title='Testing',
description='ReGrowl Test',
)
if options.test in ['subscription', 'all']:
notifier.subscribe(
'TestId',
'TestName',
1337,
)
示例6: TestHash
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
class TestHash(unittest.TestCase):
def setUp(self):
self.growl = GrowlNotifier('GNTP unittest', ['Testing'])
self.growl.register()
def test_english(self):
self.growl.notify('Testing','Testing','Hello')
def test_extra(self):
self.growl.notify('Testing','Testing','allô')
def test_japanese(self):
self.growl.notify('Testing','Testing',u'おはおう')
示例7: main
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
def main():
(options, message) = ClientParser().parse_args()
logging.basicConfig(level=options.verbose)
if not os.path.exists(DEFAULT_CONFIG):
logging.info('No config read found at %s', DEFAULT_CONFIG)
growl = GrowlNotifier(
applicationName=options.app,
notifications=[options.name],
defaultNotifications=[options.name],
hostname=options.host,
password=options.password,
port=options.port,
)
result = growl.register()
if result is not True:
exit(result)
# This would likely be better placed within the growl notifier
# class but until I make _checkIcon smarter this is "easier"
if options.icon and growl._checkIcon(options.icon) is False:
logging.info('Loading image %s', options.icon)
f = open(options.icon, 'rb')
options.icon = f.read()
f.close()
result = growl.notify(
noteType=options.name,
title=options.title,
description=message,
icon=options.icon,
sticky=options.sticky,
priority=options.priority,
callback=options.callback,
identifier=options.identifier,
)
if result is not True:
exit(result)
示例8: send_gntp_notification
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
def send_gntp_notification(self):
growl_ips = self.growl_ips
gntp_ips = self.gntp_ips
# don't send to gntp if we can use growl
gntp_ips = [ip for ip in gntp_ips if (ip not in growl_ips)]
for ip in gntp_ips:
growl = GrowlNotifier(
applicationName = 'Doorbell',
notifications = ['doorbell'],
defaultNotifications = ['doorbell'],
hostname = ip,
password = self.password,
)
result = growl.register()
if not result:
continue
result = growl.notify(
noteType = 'doorbell',
title = self.title,
description = self.description,
sticky = True,
)
示例9: main
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
def main():
(options, message) = ClientParser().parse_args()
logging.basicConfig(level=options.verbose)
growl = GrowlNotifier(
applicationName=options.app,
notifications=[options.name],
defaultNotifications=[options.name],
hostname=options.host,
password=options.password,
port=options.port,
)
result = growl.register()
if result is not True:
exit(result)
# This would likely be better placed within the growl notifier
# class but until I make _checkIcon smarter this is "easier"
if options.icon is not None and not options.icon.startswith("http"):
logging.info("Loading image %s", options.icon)
f = open(options.icon)
options.icon = f.read()
f.close()
result = growl.notify(
noteType=options.name,
title=options.title,
description=message,
icon=options.icon,
sticky=options.sticky,
priority=options.priority,
callback=options.callback,
identifier=options.identifier,
)
if result is not True:
exit(result)
示例10: ClientParser
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
if values.title == '':
values.title = message[:20]
return values, message
if __name__ == "__main__":
(options,message) = ClientParser('~/.gntp').parse_args()
growl = GrowlNotifier(
applicationName = options.app,
notifications = [options.name],
defaultNotifications = [options.name],
hostname = options.host,
password = options.password,
port = options.port,
debug = options.debug,
)
result = growl.register()
if result is not True: exit(result)
result = growl.notify(
noteType = options.name,
title = options.title,
description = message,
icon = options.icon,
sticky = options.sticky,
priority = options.priority,
)
if result is not True: exit(result)
示例11: Parser
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
dest='password',
default=None)
self.add_option('-A','--appname',
help='GNTP Application Name',
dest='app',
default=APPLICATION_NAME)
self.add_option('-v',dest='debug',
help='Print Debugging to stderr',
action='store_true',
default=False)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_exit)
parser = Parser()
(options, args) = parser.parse_args()
growl = GrowlNotifier(
applicationName = options.app,
notifications = [NOTIFICATION_NAME],
hostname = options.host,
password = options.password,
port = options.port,
debug = options.debug,
)
growl.register()
while( True ):
line = sys.stdin.readline()
if not line: break
sys.stdout.write(line)
growl.notify(NOTIFICATION_NAME,NOTIFICATION_NAME,line)
示例12: Core
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
class Core(CorePluginBase):
def growlInit(self):
# addr = (self.config['growl_host'], self.config['growl_port'])
# s = socket(AF_INET,SOCK_DGRAM)
# p = GrowlRegistrationPacket("Deluge", self.config['growl_password'])
# p.addNotification("Download Completed", True)
# p.addNotification("Torrent Added", True)
# s.sendto(p.payload(), addr)
# s.close()
self.growl = GrowlNotifier(
applicationName = "Deluge",
notifications = ["Torrent Added", "Download Completed"],
defaultNotifications = ["Torrent Added"],
hostname = self.config['growl_host'],
password = self.config['growl_password'],
port = self.config['growl_port'],
debug = 0
)
result = self.growl.register()
def sendGrowl(self, noteType, title, description, sticky=False, priority=0):
# p = GrowlNotificationPacket(application="Deluge", notification=noteType, title=title, description=description, priority=priority, sticky=sticky, password=self.config['growl_password']);
# addr = (self.config['growl_host'], self.config['growl_port'])
# s = socket(AF_INET,SOCK_DGRAM)
# s.sendto(p.payload(), addr)
# s.close()
result = self.growl.notify(
noteType = noteType,
title = title,
description = description,
icon = '',
sticky = sticky,
priority = priority
)
def enable(self):
self.config = deluge.configmanager.ConfigManager("growl.conf", DEFAULT_PREFS)
self.growlInit()
#component.get("AlertManager").register_handler("torrent_finished_alert", self.on_torrent_finished)
d = defer.Deferred()
# simulate a delayed result by asking the reactor to schedule
# gotResults in 2 seconds time
reactor.callLater(2, self.connect_events)
log.debug("Growl core plugin enabled!")
return d
def disable(self):
log.debug("Growl core plugin disabled!")
#component.get("AlertManager").deregister_handler(self.on_alert_torrent_finished)
self.disconnect_events();
self.config.save()
def update(self):
pass
def connect_events(self):
event_manager = component.get("EventManager")
event_manager.register_event_handler("TorrentFinishedEvent", self.on_torrent_finished)
event_manager.register_event_handler("TorrentAddedEvent", self.on_torrent_added)
def disconnect_events(self):
event_manager = component.get("EventManager")
event_manager.deregister_event_handler("TorrentFinishedEvent", self.on_torrent_finished)
event_manager.deregister_event_handler("TorrentAddedEvent", self.on_torrent_added)
def on_torrent_added(self, torrent_id):
if (self.config['growl_torrent_added'] == False):
return
try:
#torrent_id = str(alert.handle.info_hash())
torrent = component.get("TorrentManager")[torrent_id]
torrent_status = torrent.get_status({})
message = _("Added Torrent \"%(name)s\"") % torrent_status
d = defer.maybeDeferred(self.sendGrowl, "Torrent Added", "Torrent Added", message, self.config['growl_sticky'], self.config['growl_priority'])
#d.addCallback(self._on_notify_sucess, 'email')
#d.addErrback(self._on_notify_failure, 'email')
return d
except Exception, e:
log.error("error in alert %s" % e)
示例13: len
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
cover_art = program_icon
if len(info['coverArt']) > 0:
cover_art = info[u'coverArt']
try:
if argc < 1:
sys.exit(1)
elif event == u'songstart':
if LASTFM_NOW_PLAYING:
network.update_now_playing(artist = artist, album = album, title = title, duration = song_duration)
if NOTIFY_SONG_START:
growl.notify(
noteType=u'Song Start',
icon=cover_art,
title=u'{0}{1}'.format(
title,
loved_icon),
description=u'{0}\n{1}'.format(
artist,
album))
elif event == u'songfinish':
if LASTFM_SCROBBLE and song_duration > 1000*MIN_DURATION and (100.0 * song_played / song_duration > THRESHOLD or song_played > 1000*PLAYED_ENOUGH):
song_started = int(time.time() - song_played / 1000.0)
network.scrobble(artist = artist, title = title, timestamp = song_started)
if (LASTFM_LOVE or LASTFM_BAN) and rating > 0:
track = network.get_track(artist, title)
if LASTFM_LOVE and rating == 1:
track.love()
elif LASTFM_BAN and rating == 2:
track.ban()
if NOTIFY_SONG_END:
示例14: len
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
else:
info[u'lovedIcon'] = u''
# Set the cover art to the program icon when it's missing.
if len(info[u'coverArt']) == 0:
info[u'coverArt'] = info[u'programIcon']
try:
if argc < 1:
sys.exit(1)
elif argv[1] == u'songstart' and NOTIFY_SONG_START:
growl.notify(
noteType=u'Song Start',
icon=info[u'coverArt'],
title=u'{0}{1}'.format(
info[u'title'],
info[u'lovedIcon']),
description=u'{0}\n{1}'.format(
info[u'artist'],
info[u'album']))
elif argv[1] == u'songfinish' and NOTIFY_SONG_END:
growl.notify(
noteType=u'Song End',
icon=info[u'coverArt'],
title=u'{0}{1}'.format(
info[u'title'],
info[u'lovedIcon']),
description=u'{0}\n{1}'.format(
info[u'artist'],
info[u'album']))
elif argv[1] == u'songlove' and NOTIFY_SONG_LOVE:
示例15: __init__
# 需要导入模块: from gntp.notifier import GrowlNotifier [as 别名]
# 或者: from gntp.notifier.GrowlNotifier import notify [as 别名]
class StackOverflowFetcher:
def __init__(self):
self.base_url = 'http://stackoverflow.com/questions/tagged/'
self.get_or_create_database()
self.growl = GrowlNotifier(
applicationName='StackOverflowChecker',
notifications=['new'],)
self.growl.register()
self.tags = [('django', True), ('python', False)]
self.get_questions()
self.close_connection()
def get_questions(self):
"""
Parse target URL for new questions.
"""
while self.tags:
tag, sticky = self.tags.pop()
url = self.base_url + tag
html = urllib2.urlopen(url).read()
soup = BeautifulSoup.BeautifulSoup(html)
questions = soup.findAll('h3')
for question in questions:
element = question.find('a')
link = element.get('href')
question = element.text
if self.is_new_link(link):
self.growl.notify(
noteType = "new",
title = question,
description = question,
icon = "http://example.com/icon.png",
sticky = sticky,
priority = 1,
callback = 'http://stackoverflow.com{0}'.format(link),
)
self.record_question(link, question)
def get_or_create_database(self):
"""
Check if database file exists. Create if not.
Open file and send query.
If query fails, create tables.
"""
path = os.path.join(os.path.dirname(__file__), 'questions.db')
try:
f = open(path)
except IOError:
f = open(path, 'w')
f.close()
self.conn = sqlite3.connect(path)
try:
self.conn.execute('SELECT * from questions')
except sqlite3.OperationalError:
self.create_database()
def create_database(self):
self.conn.execute('CREATE TABLE questions(link VARCHAR(400), text VARCHAR(300));')
def is_new_link(self, link):
results = self.conn.execute('SELECT * FROM questions WHERE questions.link = "%s";' % link).fetchall()
if not results:
return True
return False
def record_question(self, link, question):
results = self.conn.execute('INSERT INTO questions(link, text) VALUES ("%s", "%s");' % (link, question))
def close_connection(self):
self.conn.commit()
self.conn.close()