amazon bills
This commit is contained in:
parent
36c001474c
commit
583923622b
3 changed files with 56 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ from requests.exceptions import Timeout, ConnectionError
|
||||||
|
|
||||||
from weboob.browser import LoginBrowser, URL, need_login
|
from weboob.browser import LoginBrowser, URL, need_login
|
||||||
from weboob.browser.exceptions import ServerError, HTTPNotFound
|
from weboob.browser.exceptions import ServerError, HTTPNotFound
|
||||||
|
from weboob.capabilities.bill import Subscription, Bill
|
||||||
from weboob.capabilities.shop import OrderNotFound
|
from weboob.capabilities.shop import OrderNotFound
|
||||||
from weboob.exceptions import BrowserIncorrectPassword
|
from weboob.exceptions import BrowserIncorrectPassword
|
||||||
|
|
||||||
|
|
@ -112,3 +113,24 @@ class Amazon(LoginBrowser):
|
||||||
except (ServerError, Timeout, ConnectionError) as e:
|
except (ServerError, Timeout, ConnectionError) as e:
|
||||||
pass
|
pass
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@need_login
|
||||||
|
def get_subscription_list(self):
|
||||||
|
sub = Subscription()
|
||||||
|
sub.label = u'amazon'
|
||||||
|
sub.id = u'amazon'
|
||||||
|
yield sub
|
||||||
|
|
||||||
|
@need_login
|
||||||
|
def iter_bills(self, subscription):
|
||||||
|
orders = self.iter_orders()
|
||||||
|
for o in orders:
|
||||||
|
b = Bill()
|
||||||
|
b._url = o._bill['url']
|
||||||
|
b.id = '%s.%s' % (subscription.id, o.id)
|
||||||
|
b.date = o.date
|
||||||
|
b.price = o.total
|
||||||
|
b.format = o._bill['format']
|
||||||
|
b.currency = self.get_currency()
|
||||||
|
b.vat = o.tax
|
||||||
|
yield b
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,16 @@ class OrderNewPage(OrderPage):
|
||||||
order.discount = self.discount()
|
order.discount = self.discount()
|
||||||
order.shipping = self.shipping()
|
order.shipping = self.shipping()
|
||||||
order.total = self.grand_total()
|
order.total = self.grand_total()
|
||||||
|
order._bill = self.bill()
|
||||||
return order
|
return order
|
||||||
|
|
||||||
|
def bill(self):
|
||||||
|
pdf = self.doc.xpath(u'//a[contains(text(), "Imprimer une facture")]')
|
||||||
|
htlm = self.doc.xpath(u'//a[contains(text(), "Imprimer un récapitulatif de commande")]')
|
||||||
|
format = u'pdf' if pdf else u'html'
|
||||||
|
url = pdf[0].attrib['href'] if pdf else htlm[0].attrib['href']
|
||||||
|
return {'url': url, 'format': format}
|
||||||
|
|
||||||
def order_date(self):
|
def order_date(self):
|
||||||
return datetime.strptime(
|
return datetime.strptime(
|
||||||
re.match(u'.*Commandé le ([0-9]+ [0-9]+ [0-9]+) .*',
|
re.match(u'.*Commandé le ([0-9]+ [0-9]+ [0-9]+) .*',
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.capabilities.bill import CapBill, Subscription, Bill, SubscriptionNotFound, BillNotFound
|
||||||
from weboob.capabilities.shop import CapShop, Order
|
from weboob.capabilities.shop import CapShop, Order
|
||||||
|
from weboob.capabilities.base import find_object
|
||||||
from weboob.tools.backend import Module, BackendConfig
|
from weboob.tools.backend import Module, BackendConfig
|
||||||
from weboob.tools.value import Value, ValueBackendPassword
|
from weboob.tools.value import Value, ValueBackendPassword
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
|
|
@ -29,7 +31,7 @@ from .fr.browser import AmazonFR
|
||||||
__all__ = ['AmazonModule']
|
__all__ = ['AmazonModule']
|
||||||
|
|
||||||
|
|
||||||
class AmazonModule(Module, CapShop):
|
class AmazonModule(Module, CapShop, CapBill):
|
||||||
NAME = 'amazon'
|
NAME = 'amazon'
|
||||||
MAINTAINER = u'Oleg Plakhotniuk'
|
MAINTAINER = u'Oleg Plakhotniuk'
|
||||||
EMAIL = 'olegus8@gmail.com'
|
EMAIL = 'olegus8@gmail.com'
|
||||||
|
|
@ -75,3 +77,26 @@ class AmazonModule(Module, CapShop):
|
||||||
if not isinstance(order, Order):
|
if not isinstance(order, Order):
|
||||||
order = self.get_order(order)
|
order = self.get_order(order)
|
||||||
return self.browser.iter_items(order)
|
return self.browser.iter_items(order)
|
||||||
|
|
||||||
|
def iter_subscription(self):
|
||||||
|
return self.browser.get_subscription_list()
|
||||||
|
|
||||||
|
def get_subscription(self, _id):
|
||||||
|
return find_object(self.iter_subscription(), id=_id, error=SubscriptionNotFound)
|
||||||
|
|
||||||
|
def get_bill(self, _id):
|
||||||
|
subid = _id.split('.')[0]
|
||||||
|
subscription = self.get_subscription(subid)
|
||||||
|
return find_object(self.iter_bills(subscription), id=_id, error=BillNotFound)
|
||||||
|
|
||||||
|
def iter_bills(self, subscription):
|
||||||
|
if not isinstance(subscription, Subscription):
|
||||||
|
subscription = self.get_subscription(subscription)
|
||||||
|
return self.browser.iter_bills(subscription)
|
||||||
|
|
||||||
|
def download_bill(self, bill):
|
||||||
|
if not isinstance(bill, Bill):
|
||||||
|
bill = self.get_bill(bill)
|
||||||
|
if bill._url:
|
||||||
|
return self.browser.open(bill._url).content
|
||||||
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue