Commit 3393fb73 authored by Romain Bignon's avatar Romain Bignon

abstraction on scheduler

parent e66f47e3
......@@ -57,9 +57,11 @@ class Backend:
raise Backend.ConfigError("Value of '%s' does not match regexp '%s'" % (name, field.regexp))
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)
if isinstance(field.default, float):
elif isinstance(field.default, float):
value = float(value)
self.config[name] = value
......@@ -22,7 +22,6 @@ import re
from import Account
from import BasePage
from import tostring
class AccountsList(BasePage):
LINKID_REGEXP = re.compile(".*ch4=(\w+).*")
......@@ -84,7 +84,7 @@ class Article(object):
date_s = unicode(subdivs[1].text)
date_s = unicode(div.find('i').tail)
print date_s
#print date_s
if div.attrib.get('class', '').startswith('bodydiv '):
self.body = tostring(div)
......@@ -48,7 +48,7 @@ class Monboob(BaseApplication):
self.weboob.schedule(self.config.get('interval'), self.process)
self.weboob.repeat(self.config.get('interval'), self.process)
def process(self):
......@@ -19,20 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os
import sched
import time
from weboob.modules import ModulesLoader
from weboob.scheduler import Scheduler
class Weboob:
WORKDIR = os.path.join(os.path.expanduser('~'), '.weboob')
def __init__(self, app_name, workdir=WORKDIR):
def __init__(self, app_name, workdir=WORKDIR, scheduler=None):
self.app_name = app_name
self.workdir = workdir
self.backends = {}
self.scheduler = sched.scheduler(time.time, time.sleep)
if scheduler is None:
scheduler = Scheduler()
self.scheduler = scheduler
self.modules_loader = ModulesLoader()
......@@ -54,7 +56,10 @@ class Weboob:
yield (name, backend)
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):
# -*- 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
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:
return True
def want_stop(self):
self.running = False
def _repeated_cb(self, interval, func, args):
self.repeat(interval, func, *args)
......@@ -33,9 +33,7 @@ except ImportError:
class HTMLTreeBuilder(HTMLParser):
def __init__(self, encoding=None):
if target is None:
target = ElementTree.TreeBuilder()
self._target = target
self._target = ElementTree.TreeBuilder()
def doctype(self, name, pubid, system):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment