Ejemplo n.º 1
0
 async def init_users():
     global_task_control = dict_task['global_task_control']
     custom_task_control = dict_task['custom_task_control']
     global_task_arrangement = dict_task['global_task_arrangement']
     custom_task_arrangement = dict_task['custom_task_arrangement']
     users = notifier.Users(global_task_control=global_task_control,
                            global_task_arrangement=global_task_arrangement,
                            dict_bili=dict_bili,
                            force_sleep=bili_sched.force_sleep)
     notifier.init(users=users)
     username = user_info['username']
     await notifier.add_user(
         user_info=user_info_copy,
         custom_task_control=custom_task_control.get(username, {}),
         custom_task_arrangement=custom_task_arrangement.get(username, {}))
Ejemplo n.º 2
0
Archivo: run.py Proyecto: BCCC0/bili2.0
async def init_users():
    global_task_control = dict_task['global_task_control']
    custom_task_control = dict_task['custom_task_control']
    global_task_arrangement = dict_task['global_task_arrangement']
    custom_task_arrangement = dict_task['custom_task_arrangement']

    users = notifier.Users(global_task_control=global_task_control,
                           global_task_arrangement=global_task_arrangement,
                           dict_bili=dict_bili,
                           force_sleep=bili_sched.force_sleep)
    notifier.init(users=users)
    assert dict_user['users']  # 这个 list 为 true 表示至少要有一个用户信息
    for user_info in dict_user['users']:
        username = user_info['username']

        await notifier.add_user(user_info=user_info,
                                custom_task_control=custom_task_control.get(username, {}),
                                custom_task_arrangement=custom_task_arrangement.get(username, {}))
	def init_notifier(self):
		# TODO: only do this, when it is really importet
		# import umcp; del sys.modules['notifier']; import module; sys.modules.get('notifier')
		# (but what if the importet module relies on notifier on import time?) → doesn't occur
		# TODO: break API: remove notifier

		# MUST be called after initializing the deamon
		implementation = self.options.notifier.lower()
		types = dict(
			qt=notifier.QT,
			generic=notifier.TWISTED
		)

		if implementation == 'qt':
			import PyQt4.Qt as qt
			qt.QCoreApplication(sys.argv)

		notifier.init(types[implementation])

		# disable notifier logging
		nflog.instance.handlers = []
		# to activate notifier logging
		nflog.set_level(nflog.DEBUG)
		nflog.open()
Ejemplo n.º 4
0
def init( module = None, force_internal=False, **options ):
    global timer_add
    global socket_add
    global dispatcher_add
    global timer_remove
    global socket_remove
    global dispatcher_remove
    global step
    global nf_socket_remove
    global nf_socket_add
    global nf_conditions
    global shutdown
    global loaded

    if not isinstance(timer_add, _Wrapper):
        raise RuntimeError('notifier already initialized')

    if not 'recursive_depth' in options:
        # default value of 2 is not enough when using async yield stuff
        options['recursive_depth'] = 5

    try:
        if force_internal:
            # pynotifier is not allowed
            raise ImportError()
        import notifier
        if notifier.loop:
            raise RuntimeError('pynotifier already initialized')
    except ImportError:
        # use our own copy of pynotifier
        from . import pynotifier as notifier

    # find a good main notifier implementation
    if not module:
        module = 'generic'
        if 'gtk' in sys.modules:
            # The gtk module is loaded, this means that we will hook
            # ourself into the gtk notifier
            module = 'gtk'
            log.info('Implicitly using gtk integration for the notifier')

    if not module in ('generic', 'gtk', 'twisted_experimental'):
        raise AttributeError('unsupported notifier %s' % module)

    if module == 'twisted_experimental':
        module = 'twisted'

    # use the selected module
    notifier.init(getattr(notifier, module.upper()), **options)

    # delete basic notifier handler
    nlog = logging.getLogger('notifier')
    for l in nlog.handlers:
        nlog.removeHandler(l)

    timer_remove = notifier.timer_remove
    timer_add = notifier.timer_add

    nf_socket_remove = notifier.socket_remove
    nf_socket_add = notifier.socket_add
    nf_conditions = [ notifier.IO_READ, notifier.IO_WRITE ]
    socket_remove = _socket_remove
    socket_add = _socket_add

    dispatcher_add = notifier.dispatcher_add
    dispatcher_remove = notifier.dispatcher_remove

    step = notifier.step

    if module == 'twisted':
        # special stop handling for twisted
        from twisted.internet import reactor
        shutdown = reactor.stop

    loaded = module
Ejemplo n.º 5
0
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

import os

import notifier

def tail_minus_f( logfile ):
	new_size = os.stat( logfile.name )[ 6 ]
	if new_size > logfile.tell():
		buffer = logfile.read( 65536 )
		if buffer: print buffer,

	return True

if __name__ == '__main__':
	notifier.init()
	filename = '/var/log/messages'
	if not os.path.isfile( filename ):
		filename = '/var/log/syslog'
	log = open( filename, 'rb' )
	log.seek( os.stat( filename )[ 6 ] )
	notifier.timer_add( 100, notifier.Callback( tail_minus_f, log ) )
	notifier.loop()
Ejemplo n.º 6
0
		self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
		self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)

		self.zoomInAct.setEnabled(self.scaleFactor < 3.0)
		self.zoomOutAct.setEnabled(self.scaleFactor > 0.333)

	def adjustScrollBar(self, scrollBar, factor):
		scrollBar.setValue(int(factor * scrollBar.value() + ((factor - 1) * scrollBar.pageStep() / 2)))


if __name__ == '__main__':
	global imageviewer
	config = ucr.ConfigRegistry()
	config.load()

	notifier.init(notifier.QT)

	parser = optparse.OptionParser()
	parser.add_option('-s', '--school', dest='school', default='711')
	parser.add_option('-r', '--room', dest='room', default='room01')
	parser.add_option('-c', '--computer', dest='computer', default='WIN7PRO')
	parser.add_option('-u', '--username', dest='username', default='Administrator')
	parser.add_option('-p', '--password', dest='password', default='univention')
	options, args = parser.parse_args()

	usl.set_credentials('uid=%s,cn=users,%s' % (options.username, config.get('ldap/base')), options.password)

	app = ViewerApp(sys.argv)
	print app.quitOnLastWindowClosed()
	app.lastWindowClosed.connect(app.quit, QtCore.Qt.DirectConnection)
	imageViewer = ImageViewer(options)
Ejemplo n.º 7
0
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

"""Simple test program for the GTK+ notifier."""

import sys

import gtk

import notifier

notifier.init( notifier.GTK )

def hello( *args ):
	print 'Hello World'

def destroy(*args):
	window.hide()
	sys.exit( 0 )

window = gtk.Window( gtk.WINDOW_TOPLEVEL )
window.connect( 'destroy', destroy )
window.set_border_width( 10 )

button = gtk.Button( 'Hello World' )
button.connect( 'clicked', hello )
window.add( button )
Ejemplo n.º 8
0
def init( module = None, force_internal=False, **options ):
    global timer_add
    global socket_add
    global dispatcher_add
    global timer_remove
    global socket_remove
    global dispatcher_remove
    global step
    global nf_socket_remove
    global nf_socket_add
    global nf_conditions
    global shutdown
    global loaded

    if not isinstance(timer_add, _Wrapper):
        raise RuntimeError('notifier already initialized')

    if not 'recursive_depth' in options:
        # default value of 2 is not enough when using async yield stuff
        options['recursive_depth'] = 5

    try:
        if force_internal:
            # pynotifier is not allowed
            raise ImportError()
        import notifier
        if notifier.loop:
            raise RuntimeError('pynotifier already initialized')
    except ImportError:
        # use our own copy of pynotifier
        from . import pynotifier as notifier

    # find a good main notifier implementation
    if not module:
        module = 'generic'
        if 'gtk' in sys.modules:
            # The gtk module is loaded, this means that we will hook
            # ourself into the gtk notifier
            module = 'gtk'
            log.info('Implicitly using gtk integration for the notifier')

    if not module in ('generic', 'gtk', 'twisted_experimental'):
        raise AttributeError('unsupported notifier %s' % module)

    if module == 'twisted_experimental':
        module = 'twisted'

    # use the selected module
    notifier.init(getattr(notifier, module.upper()), **options)

    # delete basic notifier handler
    nlog = logging.getLogger('notifier')
    for l in nlog.handlers:
        nlog.removeHandler(l)

    timer_remove = notifier.timer_remove
    timer_add = notifier.timer_add

    nf_socket_remove = notifier.socket_remove
    nf_socket_add = notifier.socket_add
    nf_conditions = [ notifier.IO_READ, notifier.IO_WRITE, notifier.IO_EXCEPT ]
    socket_remove = _socket_remove
    socket_add = _socket_add

    dispatcher_add = notifier.dispatcher_add
    dispatcher_remove = notifier.dispatcher_remove

    step = notifier.step

    if module == 'twisted':
        # special stop handling for twisted
        from twisted.internet import reactor
        shutdown = reactor.stop

    loaded = module
Ejemplo n.º 9
0
class TestSignal(signals.Provider):
    def __init__(self):
        signals.Provider.__init__(self)
        self.signal_new("test-signal")


test = TestSignal()


def timer_cb(a):
    print "timer argument", a
    signals.emit("test-signal")
    test.signal_emit("test-signal")
    print "-------------------------"
    return True


def signal_cb(signal, a, b):
    print "signal arguments", signal, a, b
    signals.disconnect("test-signal", signal_cb)


notifier.init(notifier.GENERIC)

signals.new("test-signal")
signals.connect("test-signal", notifier.Callback(signal_cb, 1, 2, "global signal"))
test.signal_connect("test-signal", notifier.Callback(signal_cb, 1, 2, "TestSignal signal"))
notifier.timer_add(2000, notifier.Callback(timer_cb, 7))

notifier.loop()
Ejemplo n.º 10
0
		self.setActiveWindow( self.dialog )

		self.button = qt.QPushButton( 'Hello World', self.dialog )
		self.dialog.show()
		qt.QObject.connect( self.button, qt.SIGNAL( 'clicked()' ), self.clickedButton )
		self.timer_id = notifier.timer_add( 1000, self.timerTest )
		self.dispatch_it = 10

	def recvQuit( self, mmsg, data = None ):
		self.quit()

	def clickedButton( self ):
		print "bye"
		self.quit( 1 )

	def timerTest( self ):
		print 'tick'
		return True

	def _dispatch( self ):
		print 'dispatch'
		self.dispatch_it -= 1
		return self.dispatch_it > 0

if __name__ == '__main__':
	notifier.init( notifier.QT )
	app = QTestApp()

	notifier.dispatcher_add( app._dispatch )
	print 'exit code: %d' % notifier.loop()
Ejemplo n.º 11
0
		EVT_BUTTON( self, 1, self.OnQuit )
		EVT_BUTTON( self, 2, self.OnSend )
		self.box.Add( self.button_send )
		self.box.Add( self.button_close )
		self.SetAutoLayout( true )
		self.SetSizer( self.box )
		self.box.Fit( self )

	def OnQuit( self, event ):
		self.parent.Close()

	def OnSend( self, event ):
		print 'Hello World!'

class MyFrame( wxFrame ):
	def __init__( self, parent ):
		wxFrame.__init__( self, parent, -1, "MyFrame" )
		self.box = wxBoxSizer( wxVERTICAL )
		self.panel = MyPanel( self, -1 )
		self.box.Add( self.panel )
		self.SetSizer( self.box )
		self.SetAutoLayout( true )
		self.box.Fit( self )

if __name__ == '__main__':
	notifier.init( notifier.WX )
	frame = MyFrame( None )
	frame.Show( true )

	notifier.loop()
Ejemplo n.º 12
0
        self.box.Add(self.button_send)
        self.box.Add(self.button_close)
        self.SetAutoLayout(true)
        self.SetSizer(self.box)
        self.box.Fit(self)

    def OnQuit(self, event):
        self.parent.Close()

    def OnSend(self, event):
        print 'Hello World!'


class MyFrame(wxFrame):
    def __init__(self, parent):
        wxFrame.__init__(self, parent, -1, "MyFrame")
        self.box = wxBoxSizer(wxVERTICAL)
        self.panel = MyPanel(self, -1)
        self.box.Add(self.panel)
        self.SetSizer(self.box)
        self.SetAutoLayout(true)
        self.box.Fit(self)


if __name__ == '__main__':
    notifier.init(notifier.WX)
    frame = MyFrame(None)
    frame.Show(true)

    notifier.loop()
Ejemplo n.º 13
0
import getlink, finder, getprevvalue, update, notifier

import flipkart, voxpop

links = getlink.init()
ans = ""
updater = ""

for link in links:
    flag = 0
    k = finder.init(link)
    if (k == "flipkart"):
        ans = flipkart.init(link)
    elif (k == "voxpop"):
        ans = voxpop.init(link)
    else:
        flag = 1
        ans = ans + "could not find for " + link + '\n'

    if flag == 0:
        updater = updater + link + " " + ans + "\n"
        if int(ans) < int(getprevvalue.init(link)):
            if int(getprevvalue.init(link)) != 10000000000000:
                notifier.init("Hurry Prices Dropped from " +
                              getprevvalue.init(link) + " to " + ans + "\n" +
                              link)
update.init(updater)
Ejemplo n.º 14
0
import time


def timeout(data):
    print 'timeout', time.time()
    print '  data    :', data

    return True


def zero(data):
    print 'timeout', time.time()
    print '  data    :', data

    return True


def dispatch(data):
    #print 'dispatch', data
    return True


# when no argument is given to init default is GENERIC
notifier.init(notifier.GENERIC, recursive_depth=5)
notifier.timer_add(1000, notifier.Callback(timeout, 'hello'))
#notifier.timer_add( 0, notifier.Callback( zero, 'hello' ) )
notifier.dispatcher_add(notifier.Callback(dispatch, 'hello'))
#notifier.dispatcher_add( notifier.Callback( dispatch, 'hello' ), False )

notifier.loop()
Ejemplo n.º 15
0
#!/usr/bin/env python3

from datetime import date, timedelta

from notifier import init, plural
from notifier.providers import EmailNotify
from prismasok import prisma
from prismasok.util import load_credentials, sorted_items, print_items, total


cardno, password = load_credentials()
p = prisma.Prisma(cardno, password)
ps = p.purchases(date.today() - timedelta(days=1))

if len(ps) > 0:
    n = init(email=EmailNotify('Prisma'))
    with n:
        n.subject = 'Prisma: {} purchase{s} yesterday'.format(len(ps), s=plural(len(ps)))
        for i, p in enumerate(ps, 1):
            data = sorted_items(p.items.data)
            print('Purchase #{}:'.format(i))
            print_items(data)
            print('Total: {}'.format(p.total))
            real_total = total(data)
            if (real_total != p.total):
                print('Real total: {}'.format(real_total))
            print()
    n.notify()
Ejemplo n.º 16
0

@nfthreads.threaded(done_with_it)
def my_thread():
    number = random.randint(50, 100)
    for i in range(number):
        time.sleep(0.1)
    if random.randint(0, 10) < 6:
        raise Exception('mysterious problem')
    return number


def doing_something_else():
    print '>>> Pick me!'
    return True


if __name__ == '__main__':
    notifier.init(notifier.GENERIC)

    _stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
    _stdout.write('Starting threads ')
    for i in range(100):
        _stdout.write('.')
        my_thread()
        time.sleep(0.02)
        _stdout.write('\033[1D*')
    _stdout.write('\n')
    notifier.timer_add(1000, doing_something_else)
    notifier.loop()
Ejemplo n.º 17
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""Simple test program for the Twisted notifier."""

import os, sys, time

#import twisted

import notifier

notifier.init(notifier.TWISTED)

_stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)


# notifier-timer testfunction
def timer_test():
    print "\ntimer_test"
    # notifier.dispatcher_add( notifier.Callback( dispatcher_test, 1, 2, 3 ) )
    return True


def timer_once():
    print "\njust once"
    return False
Ejemplo n.º 18
0
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

"""Simple test program for the Twisted notifier."""

import os, sys

#import twisted

import notifier

notifier.init( notifier.TWISTED )

def hello( *args ):
	print 'Hello World'

# notifier-timer testfunction
def timer_test():
	print "timer_test"
#	 notifier.dispatcher_add( notifier.Callback( dispatcher_test, 1, 2, 3 ) )
	return True

def dispatcher_test( a, b, c ):
	print 'dispatcher', a, b, c
	return True

def _stdin( fd ):
Ejemplo n.º 19
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""Simple test program for the GTK+ notifier."""

import sys

import gtk

import notifier

notifier.init(notifier.GTK)


def hello(*args):
    print 'Hello World'


def destroy(*args):
    window.hide()
    sys.exit(0)


window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect('destroy', destroy)
window.set_border_width(10)
Ejemplo n.º 20
0
        task_arrangement = {
            **global_task_arrangement,
            **custom_task_arrangement[username]
        }
    else:
        task_arrangement = global_task_arrangement

    user = loop.run_until_complete(
        wrap_func_as_coroutine(User,
                               dict_user=user_info,
                               task_ctrl=task_control,
                               task_arrangement=task_arrangement,
                               dict_bili=dict_bili,
                               force_sleep=bili_sched.force_sleep))
    users.append(user)
notifier.init(users=users)

# 时间间隔为小时,同时每次休眠结束都会计时归零,重新从当前时间计算时间间隔
# 下面表示每隔多少小时执行一次
bili_sched.add_daily_jobs(HeartBeatTask, every_hours=6)
bili_sched.add_daily_jobs(RecvHeartGiftTask, every_hours=6)
bili_sched.add_daily_jobs(OpenSilverBoxTask, every_hours=6)
bili_sched.add_daily_jobs(RecvDailyBagTask, every_hours=3)
bili_sched.add_daily_jobs(SignTask, every_hours=6)
bili_sched.add_daily_jobs(WatchTvTask, every_hours=6)
bili_sched.add_daily_jobs(SignFansGroupsTask, every_hours=6)
bili_sched.add_daily_jobs(SendGiftTask, every_hours=2)
bili_sched.add_daily_jobs(ExchangeSilverCoinTask, every_hours=6)
bili_sched.add_daily_jobs(JudgeCaseTask, every_hours=0.75)
bili_sched.add_daily_jobs(BiliMainTask, every_hours=4)
Ejemplo n.º 21
0
# 02110-1301 USA

import notifier

import time

def timeout( data ):
    print 'timeout', time.time()
    print '  data    :', data

    return True

def zero( data ):
    print 'timeout', time.time()
    print '  data    :', data

    return True

def dispatch( data ):
    #print 'dispatch', data
    return True

# when no argument is given to init default is GENERIC
notifier.init( notifier.GENERIC, recursive_depth = 5 )
notifier.timer_add( 1000, notifier.Callback( timeout, 'hello' ) )
#notifier.timer_add( 0, notifier.Callback( zero, 'hello' ) )
notifier.dispatcher_add( notifier.Callback( dispatch, 'hello' ) )
#notifier.dispatcher_add( notifier.Callback( dispatch, 'hello' ), False )

notifier.loop()