/modules/nettokom/module.py

https://gitlab.com/phyks/weboob · Python · 82 lines · 50 code · 14 blank · 18 comment · 9 complexity · a1de78f76448b075008e36b271f5dde1 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. # Copyright(C) 2012 Florent Fourcot
  3. #
  4. # This file is part of weboob.
  5. #
  6. # weboob is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # weboob is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
  18. from weboob.capabilities.bill import CapDocument, Subscription, SubscriptionNotFound, Detail
  19. from weboob.tools.backend import Module, BackendConfig
  20. from weboob.tools.value import ValueBackendPassword
  21. from .browser import Nettokom
  22. __all__ = ['NettoKomModule']
  23. class NettoKomModule(Module, CapDocument):
  24. NAME = 'nettokom'
  25. MAINTAINER = u'Florent Fourcot'
  26. EMAIL = 'weboob@flo.fourcot.fr'
  27. VERSION = '1.3'
  28. LICENSE = 'AGPLv3+'
  29. DESCRIPTION = 'Nettokom website'
  30. CONFIG = BackendConfig(ValueBackendPassword('login',
  31. label='Account ID (phone number)',
  32. masked=False,
  33. regexp='^(\d{8,13}|)$'),
  34. ValueBackendPassword('password',
  35. label='Password')
  36. )
  37. BROWSER = Nettokom
  38. def create_default_browser(self):
  39. return self.create_browser(self.config['login'].get(),
  40. self.config['password'].get())
  41. def iter_subscription(self):
  42. for subscription in self.browser.get_subscription_list():
  43. yield subscription
  44. def get_subscription(self, _id):
  45. with self.browser:
  46. subscription = self.browser.get_subscription(_id)
  47. if subscription:
  48. return subscription
  49. else:
  50. raise SubscriptionNotFound()
  51. def iter_documents_history(self, subscription):
  52. with self.browser:
  53. for history in self.browser.get_history():
  54. yield history
  55. # The subscription is actually useless, but maybe for the futur...
  56. def get_details(self, subscription):
  57. with self.browser:
  58. for detail in self.browser.get_details():
  59. yield detail
  60. def get_balance(self, subscription):
  61. if not isinstance(subscription, Subscription):
  62. subscription = self.get_subscription(subscription)
  63. balance = Detail()
  64. balance.id = "%s-balance" % subscription.id
  65. balance.price = subscription._balance
  66. balance.label = u"Balance %s" % subscription.id
  67. balance.currency = u'EUR'
  68. return balance