handling new website account for individual
This commit is contained in:
parent
8ce5602a72
commit
bf5dd493a8
2 changed files with 46 additions and 5 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
|
||||
from .pages import LoginPage, AccountPage, DownloadHistoryPage, LastDownloadHistoryPage, SubmitPage, HistoryParser, UselessPage, HistoryPage, CSVAlreadyAsked
|
||||
from .newpages import NewHomePage, NewAccountPage, NewHistoryPage
|
||||
from .newpages import NewHomePage, NewAccountPage, NewProHistoryPage, NewPartHistoryPage
|
||||
import datetime
|
||||
|
||||
|
||||
|
|
@ -45,8 +45,9 @@ class Paypal(Browser):
|
|||
'/cgi-bin/webscr\?cmd=_history-download-recent-submit&dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
||||
'https://www.paypal.com/webapps/business/\?nav=0.0': NewHomePage,
|
||||
'https://www.paypal.com/businessexp/money': NewAccountPage,
|
||||
'https://www.paypal.com/webapps/business/activity\?.*': NewHistoryPage,
|
||||
'https://www.paypal.com/myaccount/': NewHistoryPage,
|
||||
'https://www.paypal.com/webapps/business/activity\?.*': NewProHistoryPage,
|
||||
'https://www.paypal.com/myaccount/activity/.*': (NewPartHistoryPage, 'json'),
|
||||
'https://www.paypal.com/myaccount/': NewProHistoryPage,
|
||||
}
|
||||
|
||||
DEFAULT_TIMEOUT = 30 # CSV export is slow
|
||||
|
|
@ -60,6 +61,11 @@ class Paypal(Browser):
|
|||
self.website = "old"
|
||||
else:
|
||||
self.website = "new"
|
||||
self.location('/webapps/business/?nav=0.0')
|
||||
if self.is_on_page(NewHomePage):
|
||||
self.account_type = "pro"
|
||||
else:
|
||||
self.account_type = "perso"
|
||||
|
||||
def home(self):
|
||||
self.location('https://' + self.DOMAIN + '/en/cgi-bin/webscr?cmd=_login-run')
|
||||
|
|
@ -186,7 +192,10 @@ class Paypal(Browser):
|
|||
e = end.strftime('%d/%m/%Y')
|
||||
#Settings a big magic number so we get all transaction for the period
|
||||
LIMIT = '9999'
|
||||
self.location('/webapps/business/activity?fromdate=' + s + '&todate=' + e + '&transactiontype=ALL_TRANSACTIONS¤cy=ALL_TRANSACTIONS_CURRENCY&limit=' + LIMIT)
|
||||
if self.account_type == "pro":
|
||||
self.location('/webapps/business/activity?fromdate=' + s + '&todate=' + e + '&transactiontype=ALL_TRANSACTIONS¤cy=ALL_TRANSACTIONS_CURRENCY&limit=' + LIMIT)
|
||||
else:
|
||||
self.location('/myaccount/activity/filter?start=' + s + '&end=' + e + '&limit=' + LIMIT)
|
||||
return self.page.transaction_left()
|
||||
|
||||
def download_last_history(self, account):
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class NewAccountPage(Page):
|
|||
|
||||
return accounts
|
||||
|
||||
class NewHistoryPage(Page):
|
||||
class NewProHistoryPage(Page):
|
||||
|
||||
def iter_transactions(self, account):
|
||||
for trans in self.parse():
|
||||
|
|
@ -75,3 +75,35 @@ class NewHistoryPage(Page):
|
|||
|
||||
def transaction_left(self):
|
||||
return (len(self.document.xpath('//div[@class="no-records"]')) == 0)
|
||||
|
||||
class NewPartHistoryPage(Page):
|
||||
def transaction_left(self):
|
||||
return (len(self.document['data']['activity']['COMPLETED']) > 0 or len(self.document['data']['activity']['PENDING']) > 0)
|
||||
|
||||
def iter_transactions(self, account):
|
||||
for trans in self.parse():
|
||||
if trans._currency == account.currency:
|
||||
yield trans
|
||||
|
||||
def parse(self):
|
||||
transactions = list()
|
||||
|
||||
for status in ['PENDING', 'COMPLETED']:
|
||||
transac = self.document['data']['activity'][status]
|
||||
for t in transac:
|
||||
transactions.append(self.parse_transaction(t))
|
||||
|
||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
||||
for t in transactions:
|
||||
yield t
|
||||
|
||||
def parse_transaction(self, transaction):
|
||||
t = FrenchTransaction(transaction['activityId'])
|
||||
date = parse_french_date(transaction['date'])
|
||||
raw = transaction['counterparty']
|
||||
t.parse(date=date, raw=raw)
|
||||
amount = transaction['displayAmount']
|
||||
t.set_amount(amount)
|
||||
t._currency = transaction['currencyCode']
|
||||
return t
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue