[weboob] [PATCH 1/3] Add a new application to monitor gauges of a river

Florent Fourcot weboob at flo.fourcot.fr
Sun Feb 12 00:51:51 CET 2012


From: Florent <weboob at flo.fourcot.fr>


Signed-off-by: Florent <weboob at flo.fourcot.fr>
---
 scripts/boobgauge                          |   28 ++++++++
 weboob/applications/boobgauge/__init__.py  |   23 ++++++
 weboob/applications/boobgauge/boobgauge.py |  105 ++++++++++++++++++++++++++++
 3 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 scripts/boobgauge
 create mode 100644 weboob/applications/boobgauge/__init__.py
 create mode 100644 weboob/applications/boobgauge/boobgauge.py

diff --git a/scripts/boobgauge b/scripts/boobgauge
new file mode 100644
index 0000000..8b7a2e5
--- /dev/null
+++ b/scripts/boobgauge
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
+
+# Copyright(C) 2009-2011  Romain Bignon, Florent Fourcot
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see <http://www.gnu.org/licenses/>.
+
+
+from weboob.applications.boobgauge import Boobgauge
+
+
+if __name__ == '__main__':
+    Boobgauge.run()
+
diff --git a/weboob/applications/boobgauge/__init__.py b/weboob/applications/boobgauge/__init__.py
new file mode 100644
index 0000000..f7b474d
--- /dev/null
+++ b/weboob/applications/boobgauge/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
+
+# 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.
+
+
+from .boobgauge import Boobgauge
+
+__all__ = ['Boobgauge']
+
diff --git a/weboob/applications/boobgauge/boobgauge.py b/weboob/applications/boobgauge/boobgauge.py
new file mode 100644
index 0000000..ac754bf
--- /dev/null
+++ b/weboob/applications/boobgauge/boobgauge.py
@@ -0,0 +1,105 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010, 2011  Romain Bignon, Florent Fourcot
+#
+# 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 sys
+
+from weboob.capabilities.gauge import ICapWaterLevel, Gauge
+from weboob.tools.application.repl import ReplApplication
+
+
+__all__ = ['Boobgauge']
+
+
+class Boobgauge(ReplApplication):
+    APPNAME = 'boobgauge'
+    VERSION = '0.b'
+    COPYRIGHT = 'Copyright(C) 2010-2011 Romain Bignon, Florent Fourcot'
+    CAPS = ICapWaterLevel
+    DESCRIPTION = "Console application allowing to list the gauge lists of a river, the level, the flow..."
+    DEFAULT_FORMATTER = 'table'
+    COLLECTION_OBJECTS = (Gauge, )
+
+    def do_list(self, line):
+        """
+        list
+
+        List gauges.
+
+        Warning: display only the first "count" results (default: 10)
+        Hint: help count (or -n option for command line)
+        """
+
+        for backend, gauge in self.do('get_list'):
+            self.format(gauge)
+        self.flush()
+
+        return 0
+
+    def do_history(self, id):
+        """
+        history ID
+
+        Display history of the river level.
+        
+        Warning: display only the first "count" results (default: 10)
+        Hint: help count (or -n option for command line)
+        """
+        id, backend_name = self.parse_id(id)
+        if not id:
+            print >>sys.stderr, 'Error: please give an river ID (hint: use list command)'
+            return 2
+        names = (backend_name,) if backend_name is not None else None
+
+        def do(backend):
+            return backend.get_history(id)
+
+        for backend, level in self.do(do, backends=names):
+            self.format(level)
+        self.flush()
+
+    def do_last(self, id):
+        """
+        last ID
+
+        Display the last know value of river level and the flow if available 
+        """
+        id, backend_name = self.parse_id(id)
+        if not id:
+            print >>sys.stderr, 'Error: please give an river ID (hint: use list command)'
+            return 2
+        names = (backend_name,) if backend_name is not None else None
+
+        def do(backend):
+            return backend.last(id)
+
+        for backend, level in self.do(do, backends=names):
+            self.format(level)
+        self.flush()
+
+    def do_search(self, pattern):
+        """
+        search PATTERN
+
+        Search a gauge with the name (or the river) matching pattern (case sensitive)
+        """
+        if not pattern:
+            print >>sys.stderr, 'Error: please give a search pattern'
+            return 2
+        for bachend, gauge in self.do('search', pattern):
+            self.format(gauge)
+        self.flush()
-- 
1.7.9




More information about the weboob mailing list