/modules/freemobile/module.py

https://github.com/laurentb/weboob · Python · 93 lines · 57 code · 19 blank · 17 comment · 5 complexity · c27e588461ee0c8f422d6d5cfb9e3502 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. # Copyright(C) 2012-2014 Florent Fourcot
  3. #
  4. # This file is part of a weboob module.
  5. #
  6. # This weboob module is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Lesser 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. # This weboob module 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 Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public License
  17. # along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
  18. from weboob.capabilities.bill import DocumentTypes, CapDocument, Subscription, Bill, SubscriptionNotFound, DocumentNotFound
  19. from weboob.capabilities.profile import CapProfile
  20. from weboob.capabilities.messages import CantSendMessage, CapMessages, CapMessagesPost
  21. from weboob.capabilities.base import find_object
  22. from weboob.tools.backend import Module, BackendConfig
  23. from weboob.tools.value import ValueBackendPassword
  24. from .browser import Freemobile
  25. __all__ = ['FreeMobileModule']
  26. class FreeMobileModule(Module, CapDocument, CapMessages, CapMessagesPost, CapProfile):
  27. NAME = 'freemobile'
  28. MAINTAINER = u'Florent Fourcot'
  29. EMAIL = 'weboob@flo.fourcot.fr'
  30. VERSION = '2.1'
  31. LICENSE = 'LGPLv3+'
  32. DESCRIPTION = 'Free Mobile website'
  33. CONFIG = BackendConfig(ValueBackendPassword('login',
  34. label='Account ID',
  35. masked=False,
  36. regexp='^(\d{8}|)$'),
  37. ValueBackendPassword('password',
  38. label='Password')
  39. )
  40. BROWSER = Freemobile
  41. accepted_document_types = (DocumentTypes.BILL,)
  42. def create_default_browser(self):
  43. return self.create_browser(self.config['login'].get(),
  44. self.config['password'].get())
  45. def iter_subscription(self):
  46. return self.browser.get_subscription_list()
  47. def get_subscription(self, _id):
  48. return find_object(self.iter_subscription(), id=_id, error=SubscriptionNotFound)
  49. def iter_documents_history(self, subscription):
  50. if not isinstance(subscription, Subscription):
  51. subscription = self.get_subscription(subscription)
  52. return self.browser.get_history(subscription)
  53. def get_document(self, _id):
  54. subid = _id.split('.')[0]
  55. subscription = self.get_subscription(subid)
  56. return find_object(self.iter_documents(subscription), id=_id, error=DocumentNotFound)
  57. def iter_documents(self, subscription):
  58. if not isinstance(subscription, Subscription):
  59. subscription = self.get_subscription(subscription)
  60. return self.browser.iter_documents(subscription)
  61. def get_details(self, subscription):
  62. if not isinstance(subscription, Subscription):
  63. subscription = self.get_subscription(subscription)
  64. return self.browser.get_details(subscription)
  65. def download_document(self, bill):
  66. if not isinstance(bill, Bill):
  67. bill = self.get_document(bill)
  68. return self.browser.open(bill.url).content
  69. def post_message(self, message):
  70. if not message.content.strip():
  71. raise CantSendMessage(u'Message content is empty.')
  72. return self.browser.post_message(message)
  73. def get_profile(self):
  74. return self.browser.get_profile()