abstraction on scheduler
This commit is contained in:
parent
e66f47e3fb
commit
3393fb73e9
7 changed files with 64 additions and 14 deletions
|
|
@ -57,9 +57,11 @@ class Backend:
|
||||||
raise Backend.ConfigError("Value of '%s' does not match regexp '%s'" % (name, field.regexp))
|
raise Backend.ConfigError("Value of '%s' does not match regexp '%s'" % (name, field.regexp))
|
||||||
|
|
||||||
if not field.default is None:
|
if not field.default is None:
|
||||||
if isinstance(field.default, int):
|
if isinstance(field.default, bool):
|
||||||
|
value = value.lower() in ('1', 'true', 'on', 'yes')
|
||||||
|
elif isinstance(field.default, int):
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if isinstance(field.default, float):
|
elif isinstance(field.default, float):
|
||||||
value = float(value)
|
value = float(value)
|
||||||
self.config[name] = value
|
self.config[name] = value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import re
|
||||||
|
|
||||||
from weboob.capabilities.bank import Account
|
from weboob.capabilities.bank import Account
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.tools.parser import tostring
|
|
||||||
|
|
||||||
class AccountsList(BasePage):
|
class AccountsList(BasePage):
|
||||||
LINKID_REGEXP = re.compile(".*ch4=(\w+).*")
|
LINKID_REGEXP = re.compile(".*ch4=(\w+).*")
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ class Article(object):
|
||||||
date_s = unicode(subdivs[1].text)
|
date_s = unicode(subdivs[1].text)
|
||||||
else:
|
else:
|
||||||
date_s = unicode(div.find('i').tail)
|
date_s = unicode(div.find('i').tail)
|
||||||
print date_s
|
#print date_s
|
||||||
if div.attrib.get('class', '').startswith('bodydiv '):
|
if div.attrib.get('class', '').startswith('bodydiv '):
|
||||||
self.body = tostring(div)
|
self.body = tostring(div)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class Monboob(BaseApplication):
|
||||||
|
|
||||||
self.weboob.load_backends(ICapMessages)
|
self.weboob.load_backends(ICapMessages)
|
||||||
|
|
||||||
self.weboob.schedule(self.config.get('interval'), self.process)
|
self.weboob.repeat(self.config.get('interval'), self.process)
|
||||||
self.weboob.loop()
|
self.weboob.loop()
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
|
|
||||||
|
|
@ -19,20 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sched
|
|
||||||
import time
|
|
||||||
|
|
||||||
from weboob.modules import ModulesLoader
|
from weboob.modules import ModulesLoader
|
||||||
|
from weboob.scheduler import Scheduler
|
||||||
|
|
||||||
class Weboob:
|
class Weboob:
|
||||||
WORKDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
WORKDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
||||||
BACKENDS_FILENAME = 'backends'
|
BACKENDS_FILENAME = 'backends'
|
||||||
|
|
||||||
def __init__(self, app_name, workdir=WORKDIR):
|
def __init__(self, app_name, workdir=WORKDIR, scheduler=None):
|
||||||
self.app_name = app_name
|
self.app_name = app_name
|
||||||
self.workdir = workdir
|
self.workdir = workdir
|
||||||
self.backends = {}
|
self.backends = {}
|
||||||
self.scheduler = sched.scheduler(time.time, time.sleep)
|
|
||||||
|
if scheduler is None:
|
||||||
|
scheduler = Scheduler()
|
||||||
|
self.scheduler = scheduler
|
||||||
|
|
||||||
self.modules_loader = ModulesLoader()
|
self.modules_loader = ModulesLoader()
|
||||||
self.modules_loader.load()
|
self.modules_loader.load()
|
||||||
|
|
@ -54,7 +56,10 @@ class Weboob:
|
||||||
yield (name, backend)
|
yield (name, backend)
|
||||||
|
|
||||||
def schedule(self, interval, function, *args):
|
def schedule(self, interval, function, *args):
|
||||||
self.scheduler.enter(interval, 1, function, args)
|
return self.scheduler.schedule(interval, function, *args)
|
||||||
|
|
||||||
|
def repeat(self, interval, function, *args):
|
||||||
|
return self.scheduler.repeat(interval, function, *args)
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
self.scheduler.run()
|
return self.scheduler.run()
|
||||||
|
|
|
||||||
46
weboob/scheduler.py
Normal file
46
weboob/scheduler.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Copyright(C) 2010 Romain Bignon
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, version 3 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sched
|
||||||
|
import time
|
||||||
|
|
||||||
|
class Scheduler(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.scheduler = sched.scheduler(time.time, time.sleep)
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def schedule(self, interval, function, *args):
|
||||||
|
return self.scheduler.enter(interval, 1, function, args)
|
||||||
|
|
||||||
|
def repeat(self, interval, function, *args):
|
||||||
|
return self.scheduler.enter(interval, 1, self._repeated_cb, (interval, function, args))
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.running = True
|
||||||
|
while self.running:
|
||||||
|
self.scheduler.run()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def want_stop(self):
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def _repeated_cb(self, interval, func, args):
|
||||||
|
func(*args)
|
||||||
|
self.repeat(interval, func, *args)
|
||||||
|
|
@ -33,9 +33,7 @@ except ImportError:
|
||||||
class HTMLTreeBuilder(HTMLParser):
|
class HTMLTreeBuilder(HTMLParser):
|
||||||
def __init__(self, encoding=None):
|
def __init__(self, encoding=None):
|
||||||
HTMLParser.__init__(self)
|
HTMLParser.__init__(self)
|
||||||
if target is None:
|
self._target = ElementTree.TreeBuilder()
|
||||||
target = ElementTree.TreeBuilder()
|
|
||||||
self._target = target
|
|
||||||
|
|
||||||
def doctype(self, name, pubid, system):
|
def doctype(self, name, pubid, system):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue