Commit 2ad840e9 authored by Roger Philibert's avatar Roger Philibert Committed by Romain Bignon
Browse files

contrib: blind woob replacements

parent daa513be
Pipeline #284551443 passed with stages
in 62 minutes and 47 seconds
......@@ -2,7 +2,7 @@ Woob
==========
Woob is a project which provides a core library, modules and applications
such as boobank.
such as woob bank.
Overview
--------
......
......@@ -9,12 +9,12 @@
from gi.repository import GObject, Gtk, Notify
from pkg_resources import resource_filename
from weboob.capabilities import UserError
from weboob.capabilities.bank import Account, CapBank
from weboob.core import CallErrors, Weboob
from weboob.exceptions import BrowserForbidden, BrowserIncorrectPassword, BrowserSSLError, BrowserUnavailable
from weboob.tools.application.base import MoreResultsAvailable
from weboob.tools.compat import unicode
from woob.capabilities import UserError
from woob.capabilities.bank import Account, CapBank
from woob.core import CallErrors, Woob
from woob.exceptions import BrowserForbidden, BrowserIncorrectPassword, BrowserSSLError, BrowserUnavailable
from woob.tools.application.base import MoreResultsAvailable
from woob.tools.compat import unicode
PING_FREQUENCY = 3600 # seconds
APPINDICATOR_ID = "boobank_indicator"
......@@ -32,16 +32,16 @@ def create_image_menu_item(label, image):
class BoobankTransactionsChecker(Thread):
def __init__(self, weboob, menu, account):
def __init__(self, woob, menu, account):
Thread.__init__(self)
self.weboob = weboob
self.woob = woob
self.menu = menu
self.account = account
def run(self):
account_history_menu = Gtk.Menu()
for tr in self.weboob.do('iter_history', self.account, backends=self.account.backend):
for tr in self.woob.do('iter_history', self.account, backends=self.account.backend):
label = u'%s - %s: %s%s' % (tr.date, tr.label, tr.amount, self.account.currency_text)
image = "green_light.png" if tr.amount > 0 else "red_light.png"
transaction_item = create_image_menu_item(label, image)
......@@ -62,12 +62,12 @@ def __init__(self):
self.ind.set_menu(self.menu)
logging.basicConfig()
if 'weboob_path' in os.environ:
self.weboob = Weboob(os.environ['weboob_path'])
if 'woob_path' in os.environ:
self.woob = Woob(os.environ['woob_path'])
else:
self.weboob = Weboob()
self.woob = Woob()
self.weboob.load_backends(CapBank)
self.woob.load_backends(CapBank)
def clean_menu(self, menu):
for i in menu.get_children():
......@@ -85,7 +85,7 @@ def check_boobank(self):
threads = []
try:
for account in self.weboob.do('iter_accounts'):
for account in self.woob.do('iter_accounts'):
balance = account.balance
if account.coming:
......@@ -100,7 +100,7 @@ def check_boobank(self):
currency = account.currency_text
label = "%s: %s%s" % (account.label, balance, account.currency_text)
account_item = create_image_menu_item(label, image)
thread = BoobankTransactionsChecker(self.weboob, account_item, account)
thread = BoobankTransactionsChecker(self.woob, account_item, account)
thread.start()
threads.append(thread)
......
......@@ -35,16 +35,16 @@
from dateutil.parser import parse as parse_date
from irc.bot import SingleServerIRCBot
from weboob.browser import Browser
from weboob.browser.exceptions import HTTPNotFound
from weboob.browser.pages import HTMLPage
from weboob.core import Weboob
from weboob.exceptions import BrowserHTTPError, BrowserUnavailable
from weboob.tools.application.base import ApplicationStorage
from weboob.tools.misc import get_backtrace, to_unicode
from weboob.tools.storage import StandardStorage
IRC_CHANNELS = os.getenv('BOOBOT_CHANNELS', '#weboob').split(',')
from woob.browser import Browser
from woob.browser.exceptions import HTTPNotFound
from woob.browser.pages import HTMLPage
from woob.core import Woob
from woob.exceptions import BrowserHTTPError, BrowserUnavailable
from woob.tools.application.base import ApplicationStorage
from woob.tools.misc import get_backtrace, to_unicode
from woob.tools.storage import StandardStorage
IRC_CHANNELS = os.getenv('BOOBOT_CHANNELS', '#woob').split(',')
IRC_NICKNAME = os.getenv('BOOBOT_NICKNAME', 'boobot')
IRC_SERVER = os.getenv('BOOBOT_SERVER', 'dickson.freenode.net')
IRC_IGNORE = [re.compile(i) for i in os.getenv('BOOBOT_IGNORE', '!~?irker@').split(',')]
......@@ -153,28 +153,25 @@ class MyThread(Thread):
def __init__(self, bot):
Thread.__init__(self)
self.weboob = Weboob(storage=StandardStorage(STORAGE_FILE))
self.weboob.load_backends()
self.woob = Woob(storage=StandardStorage(STORAGE_FILE))
self.woob.load_backends()
self.bot = bot
self.bot.set_weboob(self.weboob)
self.bot.set_woob(self.woob)
def run(self):
for ev in self.bot.joined.values():
ev.wait()
self.weboob.repeat(5, self.check_tasks)
self.weboob.repeat(300, self.check_board)
self.weboob.repeat(600, self.check_dlfp)
self.weboob.repeat(600, self.check_twitter)
self.woob.repeat(5, self.check_tasks)
self.woob.repeat(300, self.check_board)
self.woob.repeat(600, self.check_dlfp)
self.woob.repeat(600, self.check_twitter)
self.weboob.loop()
self.woob.loop()
def find_keywords(self, text):
for word in [
'weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg',
'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', 'handjoob',
'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs',
'webcontentedit', 'weboorrents', 'assnet',
'woob', 'weboob',
'budget insight', 'budget-insight', 'budgetinsight', 'budgea']:
if word in text.lower():
return word
......@@ -183,8 +180,8 @@ def find_keywords(self, text):
def check_twitter(self):
nb_tweets = 10
for backend in self.weboob.iter_backends(module='twitter'):
for thread in list(itertools.islice(backend.iter_resources(None, ['search', 'weboob']),
for backend in self.woob.iter_backends(module='twitter'):
for thread in list(itertools.islice(backend.iter_resources(None, ['search', 'woob']),
0,
nb_tweets)):
......@@ -203,19 +200,19 @@ def check_twitter(self):
backend.set_message_read(backend.fill_thread(thread, ['root']).root)
def check_dlfp(self):
for msg in self.weboob.do('iter_unread_messages', backends=['dlfp']):
for msg in self.woob.do('iter_unread_messages', backends=['dlfp']):
word = self.find_keywords(msg.content)
if word is not None:
url = msg.signature[msg.signature.find('https://linuxfr'):]
self.bot.send_message('[DLFP] %s talks about %s: %s' % (
msg.sender, word, url))
self.weboob[msg.backend].set_message_read(msg)
self.woob[msg.backend].set_message_read(msg)
def check_board(self):
def iter_messages(backend):
return backend.browser.iter_new_board_messages()
for msg in self.weboob.do(iter_messages, backends=['dlfp']):
for msg in self.woob.do(iter_messages, backends=['dlfp']):
word = self.find_keywords(msg.message)
if word is not None and msg.login != 'moules':
message = msg.message.replace(word, '\002%s\002' % word)
......@@ -228,8 +225,8 @@ def check_tasks(self):
self.bot.tasks_queue.remove(task)
def stop(self):
self.weboob.want_stop()
self.weboob.deinit()
self.woob.want_stop()
self.woob.deinit()
class Boobot(SingleServerIRCBot):
......@@ -244,14 +241,14 @@ def __init__(self, channels, nickname, server, port=6667):
self.joined = dict()
for channel in channels:
self.joined[channel] = Event()
self.weboob = None
self.woob = None
self.storage = None
self.tasks_queue = []
def set_weboob(self, weboob):
self.weboob = weboob
self.storage = ApplicationStorage('boobot', weboob.storage)
def set_woob(self, woob):
self.woob = woob
self.storage = ApplicationStorage('boobot', woob.storage)
self.storage.load({})
def on_welcome(self, c, event):
......@@ -369,8 +366,8 @@ def cmd_getquote(self, nick, channel, text):
def on_boobid(self, boobid):
_id, backend_name = boobid.split('@', 1)
if backend_name in self.weboob.backend_instances:
backend = self.weboob.backend_instances[backend_name]
if backend_name in self.woob.backend_instances:
backend = self.woob.backend_instances[backend_name]
for cap in backend.iter_caps():
func = 'obj_info_%s' % cap.__name__[3:].lower()
if hasattr(self, func):
......
......@@ -25,8 +25,8 @@
import ConfigParser
from weboob.core import Weboob
from weboob.capabilities.video import CapVideo
from woob.core import Woob
from woob.capabilities.video import CapVideo
# hack to workaround bash redirection and encoding problem
import sys
......@@ -62,9 +62,9 @@ def __init__(self, backend_name, download_directory, links_directory):
self.links_directory = links_directory
self.backend_name = backend_name
self.backend = None
self.weboob = Weboob()
self.weboob.load_backends(modules=[self.backend_name])
self.backend = self.weboob.get_backend(self.backend_name)
self.woob = Woob()
self.woob.load_backends(modules=[self.backend_name])
self.backend = self.woob.get_backend(self.backend_name)
def purge(self):
if not os.path.isdir(self.links_directory):
......
......@@ -25,8 +25,8 @@
except ImportError as e:
from pysqlite2 import dbapi2 as sqlite
from weboob.core import Weboob
from weboob.exceptions import ModuleLoadError
from woob.core import Woob
from woob.exceptions import ModuleLoadError
import sys
import logging
level = logging.DEBUG
......@@ -34,9 +34,9 @@
def main(filename):
weboob = Weboob()
woob = Woob()
try:
hds = weboob.build_backend('hds')
hds = woob.build_backend('hds')
except ModuleLoadError as e:
print('Unable to load "hds" module: %s' % e, file=sys.stderr)
return 1
......
......@@ -26,17 +26,17 @@ import sys
import locale
import time
import logging
from weboob.core import Weboob, CallErrors
from weboob.capabilities.bank import CapBank
from weboob.exceptions import BrowserIncorrectPassword
from woob.core import Woob, CallErrors
from woob.capabilities.bank import CapBank
from woob.exceptions import BrowserIncorrectPassword
class BoobankMuninPlugin(object):
def __init__(self):
if 'weboob_path' in os.environ:
self.weboob = Weboob(os.environ['weboob_path'])
if 'woob_path' in os.environ:
self.woob = Woob(os.environ['woob_path'])
else:
self.weboob = Weboob()
self.woob = Woob()
self.monitored_accounts = None
if 'boobank_monitored' in os.environ:
self.monitored_accounts = os.environ['boobank_monitored'].split(' ')
......@@ -57,8 +57,8 @@ class BoobankMuninPlugin(object):
print('user romain')
print('group romain')
print('env.HOME /home/romain')
print('# The weboob directory path.')
print('env.weboob_path /home/romain/.config/weboob/')
print('# The woob directory path.')
print('env.woob_path /home/romain/.config/woob/')
print('# Monitored accounts. If this parameter is missing, all accounts')
print('# will be displayed.')
print('env.boobank_monitored 0125XXXXXXXXXXXX@bnporc 0125XXXXXXXXXXXX@bnporc')
......@@ -82,7 +82,7 @@ class BoobankMuninPlugin(object):
pass
def cachepath(self, name):
tmpdir = os.path.join(self.weboob.workdir, "munin")
tmpdir = os.path.join(self.woob.workdir, "munin")
if not os.path.isdir(tmpdir):
os.makedirs(tmpdir)
......@@ -138,16 +138,16 @@ class BoobankMuninPlugin(object):
return
self.new_cache('boobank-munin-config')
self.weboob.load_backends(CapBank)
self.woob.load_backends(CapBank)
self.write_output('graph_title Bank accounts')
self.write_output('graph_vlabel balance')
self.write_output('graph_category weboob')
self.write_output('graph_category woob')
self.write_output('graph_args -l 0')
try:
accounts = []
if self.monitored_accounts is not None:
d = {}
for account in self.weboob.do('iter_accounts'):
for account in self.woob.do('iter_accounts'):
if self.monitored(account):
d['%s@%s' % (account.id, account.backend)] = account
......@@ -157,7 +157,7 @@ class BoobankMuninPlugin(object):
except KeyError:
pass
else:
accounts = reversed([a for a in self.weboob.do('iter_accounts')])
accounts = reversed([a for a in self.woob.do('iter_accounts')])
first = True
for account in accounts:
......@@ -185,16 +185,16 @@ class BoobankMuninPlugin(object):
for backend, err, backtrace in errors:
print((u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace'), file=sys.stderr)
if isinstance(err, BrowserIncorrectPassword):
self.weboob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'})
self.woob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'})
def execute(self):
if self.check_cache('boobank-munin'):
return
self.new_cache('boobank-munin')
self.weboob.load_backends(CapBank)
self.woob.load_backends(CapBank)
try:
for account in self.weboob.do('iter_accounts'):
for account in self.woob.do('iter_accounts'):
if self.monitored(account):
balance = account.balance
if account.coming and self.add_coming:
......
......@@ -52,7 +52,7 @@ use English qw(-no_match_vars);
use Encode;
my @monitored = split / /, $ENV{'freemonitored'} || 'voice sms';
my $cachedir = $ENV{'HOME'} . '/.config/weboob/munin/';
my $cachedir = $ENV{'HOME'} . '/.config/woob/munin/';
my $cachefile = "$cachedir/freemobile-munin";
my $refreshtime = $ENV{'cache_expire'} || 10_800;
......@@ -64,7 +64,7 @@ if (length($phone) > 0) {
$account = $phone . '@freemobile';
}
my $weboob = 'boobill -f table -b freemobile details ' . $account;
my $woob = 'woob bill -f table -b freemobile details ' . $account;
my $cache_fh;
my %label = (
......@@ -156,7 +156,7 @@ sub config {
print <<'EOF';
graph_title Conso Free
graph_vlabel Suivi conso du forfait Free Mobile
graph_category weboob
graph_category woob
graph_args -l 0
EOF
foreach (@monitored) {
......@@ -183,7 +183,7 @@ sub fetch {
}
}
# execute woob
open my $data, q(-|), $weboob or croak "Couldn't execute program: $ERRNO";
open my $data, q(-|), $woob or croak "Couldn't execute program: $ERRNO";
my @lines = <$data>;
close $data or carp "unable to close: $ERRNO";
# If error output, print the cache (if exist) and exit
......
......@@ -26,10 +26,10 @@ C<user> I<required>: user with nettokom backend configured
C<env.HOME> I<required>: path to user home
C<env.monitored> I<required>: phone number to generated the weboob ID
C<env.monitored> I<required>: phone number to generated the woob ID
C<env.exclude> (optional): default nothing
We can exclude some boobill output. The filter is on the label.
We can exclude some woob bill output. The filter is on the label.
Some examples:
* festnetz community sms smsinsausland O2
......@@ -60,12 +60,12 @@ if ($id eq '') {
$id = $id . '@nettokom';
my @exclude = split / /, $ENV{'exclude'} || '';
my $cachedir = $ENV{'HOME'} . '/.config/weboob/munin/';
my $cachedir = $ENV{'HOME'} . '/.config/woob/munin/';
my $cachefile = "$cachedir/nettokom-munin";
my $cacheconfigfile = "$cachedir/nettokom-munin-config";
my $refreshtime = $ENV{'cache_expire'} || 10800;
my $weboob = "/usr/bin/env boobill details $id -f table";
my $woob = "/usr/bin/env woob bill details $id -f table";
my @knowlabels = ("AbgehendeSMSimAusland", "AnkommendeGespr_cheimAusland",
"Community", "D1", "D2", "Deutschland", "Festnetz",
"FreeCall", "Mailbox", "O2", "SMS", "SMSinsAusland");
......@@ -93,7 +93,7 @@ sub printconfig {
doubleprint <<'EOF';
graph_title Conso Nettokom
graph_vlabel Nettokom Verbindungs
graph_category weboob
graph_category woob
graph_args -l 0
EOF
......@@ -160,8 +160,8 @@ sub execute {
}
}
}
# execute weboob
open my $data, q(-|), $weboob or croak "Couldn't execute program: $ERRNO";
# execute woob
open my $data, q(-|), $woob or croak "Couldn't execute program: $ERRNO";
my @lines = <$data>;
close $data or carp "unable to close: $ERRNO";
# If error output, print the cache (if exist) and exit
......
......@@ -21,7 +21,7 @@
# 1) Create a symlink from /etc/munin/plugins/yourchoice to the script
# 2) Configure the plugin in /etc/munin/plugin-conf.d/ See below for the options
# 3) Restart/reload munin-node
# 4) Note that cached values are stored in folder ~/.config/weboob/munin/
# 4) Note that cached values are stored in folder ~/.config/woob/munin/
### Configuration ###
## Mandatory options ##
......@@ -51,7 +51,7 @@
# Example: env.exclude 550810@sachsen
#
# env.cache_expire: To avoid site flooding, results are cached in folder
# /.config/weboob/munin/. The default lifetime of a cache value is 3600s
# /.config/woob/munin/. The default lifetime of a cache value is 3600s
# Example: env.cache_expire 7200
#
# env.cumulate: Display data in Area mode (default) or in line mode.
......@@ -77,7 +77,7 @@
# and a better choice can be possible
# Example: env.label id
#
# env.category: set the graph category (default: weboob)
# env.category: set the graph category (default: woob)
# Example: env.category bank
# For some running examples, see at the end of the script
......@@ -88,17 +88,17 @@ import sys
import locale
import time
import logging
from weboob.capabilities.base import NotAvailable
from weboob.core import Weboob, CallErrors
from weboob.exceptions import BrowserIncorrectPassword
from woob.capabilities.base import NotAvailable
from woob.core import Woob, CallErrors
from woob.exceptions import BrowserIncorrectPassword
class GenericMuninPlugin(object):
def __init__(self):
if 'weboob_path' in os.environ:
self.weboob = Weboob(os.environ['weboob_path'])
if 'woob_path' in os.environ:
self.woob = Woob(os.environ['woob_path'])
else:
self.weboob = Weboob()
self.woob = Woob()
self.cache_expire = long(os.environ.get('cache_expire', 3600))
self.cumulate = int(os.environ.get('cumulate', 1))
self.cache = None
......@@ -108,7 +108,7 @@ class GenericMuninPlugin(object):
# Capability to load
self.capa = os.environ['capa']
# Command to pass to Weboob
# Command to pass to Woob
self.do = os.environ['do'].split(',')
# Not easy to load modules automatically...
self.mimport = os.environ["import"]
......@@ -137,7 +137,7 @@ class GenericMuninPlugin(object):
self.vlabel = self.attribvalue
if 'vlabel' in os.environ:
self.vlabel = os.environ['vlabel'].decode('utf-8')
self.category = "weboob"
self.category = "woob"
if 'category' in os.environ:
self.category = os.environ['category'].decode('utf-8')
......@@ -154,8 +154,8 @@ class GenericMuninPlugin(object):
print('user romain')
print('group romain')
print('env.HOME /home/romain')
print('# The weboob directory path.')
print('env.weboob_path /home/romain/.config/weboob/')
print('# The woob directory path.')
print('env.woob_path /home/romain/.config/woob/')
print('# Monitored objects. If this parameter is missing, all objects')
print('# will be displayed.')
print('env.id_monitored myid@backend1 otherid@backend2')
......@@ -167,7 +167,7 @@ class GenericMuninPlugin(object):
print('')
def cachepath(self, name):
tmpdir = os.path.join(self.weboob.workdir, "munin")
tmpdir = os.path.join(self.woob.workdir, "munin")
if not os.path.isdir(tmpdir):
os.makedirs(tmpdir)
......@@ -221,23 +221,23 @@ class GenericMuninPlugin(object):
def build_do(self):
if self.object_list:
results = []
for result in self.weboob.do(self.object_list):
for result in self.woob.do(self.object_list):
results.append(result)
for result in results:
try:
for i in self.weboob.do(self.do[0], result.id, backends=result.backend):
for i in self.woob.do(self.do[0], result.id, backends=result.backend):
yield i
# Do not crash if one module does not implement the feature
except CallErrors:
pass
elif len(self.do) == 1:
for i in self.weboob.do(self.do[0]):
for i in self.woob.do(self.do[0]):
yield i
elif len(self.do) == 2:
for i in self.weboob.do(self.do[0], self.do[1]):
for i in self.woob.do(self.do[0], self.do[1]):
yield i
elif len(self.do) == 3:
for i in self.weboob.do(self.do[0], self.do[1], backends=self.do[2]):
for i in self.woob.do(self.do[0], self.do[1], backends=self.do[2]):
yield i
def get_value(self, result):
......@@ -249,12 +249,12 @@ class GenericMuninPlugin(object):
return result
def monitored(self, result):
id = self.result2weboobid(result)
id = self.result2woobid(result)
if self.exclude and id in self.exclude:
return False
return not self.tomonitore or id in self.tomonitore
def result2weboobid(self, result):
def result2woobid(self, result):
attribs = self.attribid.split('/')
id = '%s@%s' % (getattr(result, attribs[0]), result.backend)
return id
......@@ -272,7 +272,7 @@ class GenericMuninPlugin(object):
return
self.new_cache('%s-config' % self.name)
self.weboob.load_backends(self.capa)
self.woob.load_backends(self.capa)
self.write_output('graph_title %s' % self.title.encode('iso-8859-15'))
self.write_output('graph_vlabel %s' % self.vlabel.encode('iso-8859-15'))
self.write_output('graph_category %s' % self.category)
......@@ -285,7 +285,7 @@ class GenericMuninPlugin(object):
d = {}
for result in self.build_do():
if self.monitored(result):
d[self.result2weboobid(result)] = result
d[self.result2woobid(result)] = result
if self.tomonitore:
for id in self.tomonitore:
......@@ -319,14 +319,14 @@ class GenericMuninPlugin(object):
for backend, err, backtrace in errors:
print((u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace'), file=sys.stderr)
if isinstance(err, BrowserIncorrectPassword):
self.weboob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'})
self.woob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'})
def execute(self):