本文整理匯總了Python中weboob.tools.ordereddict.OrderedDict類的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict類的具體用法?Python OrderedDict怎麽用?Python OrderedDict使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了OrderedDict類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_loan_list
def get_loan_list(self):
accounts = OrderedDict()
# New website
for table in self.document.xpath('//div[@class="panel"]'):
title = table.getprevious()
if title is None:
continue
account_type = self.ACCOUNT_TYPES.get(self.parser.tocleanstring(title), Account.TYPE_UNKNOWN)
for tr in table.xpath('./table/tbody/tr[contains(@id,"MM_SYNTHESE_CREDITS") and contains(@id,"IdTrGlobal")]'):
tds = tr.findall('td')
if len(tds) == 0 :
continue
for i in tds[0].xpath('.//a/strong'):
label = i.text.strip()
break
balance = Decimal(FrenchTransaction.clean_amount(self.parser.tocleanstring(tds[-1])))
account = Account()
account.id = label.split(' ')[-1]
account.label = unicode(label)
account.type = account_type
account.balance = -abs(balance)
account.currency = account.get_currency(self.parser.tocleanstring(tds[-1]))
account._card_links = []
accounts[account.id] = account
return accounts.itervalues()
示例2: format
def format(self, obj, selected_fields=None):
"""
Format an object to be human-readable.
An object has fields which can be selected.
If the object provides an iter_fields() method, the formatter will
call it. It can be used to specify the fields order.
@param obj [object] object to format
@param selected_fields [tuple] fields to display. If None, all fields are selected
@return a string of the formatted object
"""
assert isinstance(obj, (dict, CapBaseObject, tuple))
if isinstance(obj, dict):
item = obj
elif isinstance(obj, tuple):
item = OrderedDict([(k, v) for k, v in obj])
else:
item = self.to_dict(obj, selected_fields)
if item is None:
return None
if self.MANDATORY_FIELDS:
missing_fields = set(self.MANDATORY_FIELDS) - set(item.keys())
if missing_fields:
raise MandatoryFieldsNotFound(missing_fields)
formatted = self.format_dict(item=item)
if formatted:
self.after_format(formatted)
return formatted
示例3: get_list
def get_list(self):
accounts = OrderedDict()
for tr in self.document.getiterator('tr'):
first_td = tr.getchildren()[0]
if (first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g') \
and first_td.find('a') is not None:
a = first_td.find('a')
link = a.get('href', '')
if link.startswith('POR_SyntheseLst'):
continue
url = urlparse(link)
p = parse_qs(url.query)
if not 'rib' in p:
continue
for i in (2,1):
balance = FrenchTransaction.clean_amount(tr.getchildren()[i].text)
currency = Account.get_currency(tr.getchildren()[i].text)
if len(balance) > 0:
break
balance = Decimal(balance)
id = p['rib'][0]
if id in accounts:
account = accounts[id]
if not account.coming:
account.coming = Decimal('0.0')
account.coming += balance
account._card_links.append(link)
continue
account = Account()
account.id = id
account.label = unicode(a.text).strip().lstrip(' 0123456789').title()
account._link_id = link
account._card_links = []
# Find accounting amount
page = self.browser.get_document(self.browser.openurl(link))
coming = self.find_amount(page, u"Opérations à venir")
accounting = self.find_amount(page, u"Solde comptable")
if accounting is not None and accounting + (coming or Decimal('0')) != balance:
self.logger.warning('%s + %s != %s' % (accounting, coming, balance))
if accounting is not None:
balance = accounting
if coming is not None:
account.coming = coming
account.balance = balance
account.currency = currency
accounts[account.id] = account
return accounts.itervalues()
示例4: get_list
def get_list(self):
accounts = OrderedDict()
# Old website
for table in self.document.xpath('//table[@cellpadding="1"]'):
account_type = Account.TYPE_UNKNOWN
for tr in table.xpath('./tr'):
tds = tr.findall('td')
if tr.attrib.get('class', '') == 'DataGridHeader':
account_type = self.ACCOUNT_TYPES.get(tds[1].text.strip(), Account.TYPE_UNKNOWN)
else:
label = ''
i = 1
a = None
while label == '' and i < len(tds):
a = tds[i].find('a')
if a is None:
continue
label = self.parser.tocleanstring(a)
i += 1
balance = ''
i = -1
while balance == '' and i > -len(tds):
try:
balance = self.parser.tocleanstring(tds[i].xpath('./a')[0])
except KeyError:
balance = u''.join([txt.strip() for txt in tds[i].itertext()])
i -= 1
self._add_account(accounts, a, label, account_type, balance)
if len(accounts) == 0:
# New website
for table in self.document.xpath('//div[@class="panel"]'):
title = table.getprevious()
if title is None:
continue
account_type = self.ACCOUNT_TYPES.get(self.parser.tocleanstring(title), Account.TYPE_UNKNOWN)
for tr in table.xpath('.//tr'):
tds = tr.findall('td')
for i in xrange(len(tds)):
a = tds[i].find('a')
if a is not None:
break
if a is None:
continue
label = self.parser.tocleanstring(tds[0])
balance = self.parser.tocleanstring(tds[-1])
self._add_account(accounts, a, label, account_type, balance)
return accounts.itervalues()
示例5: get_profile
def get_profile(self):
title = self.parser.select(self.document.getroot(), 'title', 1)
if title.text == 'OkCupid: Account Not Found':
return None
profile = {}
profile['id'] = unicode(title.text[len('OkCupid: '):])
profile['data'] = OrderedDict()
profile_p = self.parser.select(self.document.getroot(), "//div[@id='page_content']//p", method='xpath')
profile['data']['infos'] = ProfileNode('infos', u'Informations', OrderedDict(), flags=ProfileNode.SECTION)
info = {
'age' : unicode(profile_p[1].text.split(' / ')[0]),
'sex' : unicode(profile_p[1].text.split(' / ')[1]),
'orientation' : unicode(profile_p[1].text.split(' / ')[2]),
'relationship' : unicode(profile_p[1].text.split(' / ')[3]),
}
for key, val in info.iteritems():
profile['data']['infos'].value[key] = ProfileNode(key, key.capitalize(), val)
div_essays = self.parser.select(self.document.getroot(), "//div[@class='essay']", method='xpath')
h3_essays = self.parser.select(self.document.getroot(), "//div[@id='page_content']//h3", method='xpath')
essays = OrderedDict(zip(h3_essays, div_essays))
profile['data']['look_for'] = ProfileNode('look_for', u'Look for', OrderedDict(), flags=ProfileNode.SECTION)
profile['data']['details'] = ProfileNode('details', u'Details', OrderedDict(), flags=ProfileNode.SECTION)
profile['data']['essays'] = ProfileNode('essays', u'Essays', OrderedDict(), flags=ProfileNode.SECTION)
for label, val in essays.iteritems():
label = unicode(label.text).strip()
txt = self.parser.tocleanstring(val)
if 'looking for' in label:
for i, li in enumerate(val.xpath('.//li')):
profile['data']['look_for'].value['look_for_%s' % i] = ProfileNode('look_for_%s' % i, '', li.text.strip())
elif 'summary' in label and 'summary' not in profile:
profile['summary'] = txt
else:
key = label.replace(' ', '_')
profile['data']['essays'].value[key] = ProfileNode(key, label, txt)
details_div = self.parser.select(self.document.getroot(), "//div[@id='details']//li", method='xpath')
for elem in details_div:
label = unicode(elem.getchildren()[0].text.strip())
val = unicode(elem.getchildren()[1].text.strip())
key = label.lower().replace(' ', '_')
profile['data']['details'].value[key] = ProfileNode(key, label, val)
return profile
示例6: get_list
def get_list(self):
accounts = OrderedDict()
# Old website
for table in self.document.xpath('//table[@cellpadding="1"]'):
account_type = Account.TYPE_UNKNOWN
for tr in table.xpath('./tr'):
tds = tr.findall('td')
if tr.attrib.get('class', '') == 'DataGridHeader':
account_type = self.ACCOUNT_TYPES.get(tds[1].text.strip()) or\
self.ACCOUNT_TYPES.get(self.parser.tocleanstring(tds[2])) or\
self.ACCOUNT_TYPES.get(self.parser.tocleanstring(tds[3]), Account.TYPE_UNKNOWN)
else:
# On the same row, there are many accounts (for example a
# check accound and a card one).
if len(tds) > 4:
for i, a in enumerate(tds[2].xpath('./a')):
label = self.parser.tocleanstring(a)
balance = self.parser.tocleanstring(tds[-2].xpath('./a')[i])
self._add_account(accounts, a, label, account_type, balance)
# Only 4 tds on banque de la reunion website.
elif len(tds) == 4:
for i, a in enumerate(tds[1].xpath('./a')):
label = self.parser.tocleanstring(a)
balance = self.parser.tocleanstring(tds[-1].xpath('./a')[i])
self._add_account(accounts, a, label, account_type, balance)
if len(accounts) == 0:
# New website
for table in self.document.xpath('//div[@class="panel"]'):
title = table.getprevious()
if title is None:
continue
account_type = self.ACCOUNT_TYPES.get(self.parser.tocleanstring(title), Account.TYPE_UNKNOWN)
for tr in table.xpath('.//tr'):
tds = tr.findall('td')
for i in xrange(len(tds)):
a = tds[i].find('a')
if a is not None:
break
if a is None:
continue
label = self.parser.tocleanstring(tds[0])
balance = self.parser.tocleanstring(tds[-1])
self._add_account(accounts, a, label, account_type, balance)
return accounts.itervalues()
示例7: on_loaded
def on_loaded(self):
self.accounts = OrderedDict()
self.parse_table('comptes', Account.TYPE_CHECKING)
self.parse_table('comptesEpargne', Account.TYPE_SAVINGS)
self.parse_table('comptesTitres', Account.TYPE_MARKET)
self.parse_table('comptesVie', Account.TYPE_DEPOSIT)
self.parse_table('comptesRetraireEuros')
示例8: on_loaded
def on_loaded(self):
self.accounts = OrderedDict()
self.parse_table("comptes")
self.parse_table("comptesEpargne")
self.parse_table("comptesTitres")
self.parse_table("comptesVie")
self.parse_table("comptesRetraireEuros")
示例9: AccountList
class AccountList(Page):
def on_loaded(self):
if self.document.xpath(u'//h2[text()="%s"]' % u'ERREUR'):
raise BrowserUnavailable()
self.accounts = OrderedDict()
self.parse_table('comptes', Account.TYPE_CHECKING)
self.parse_table('comptesEpargne', Account.TYPE_SAVINGS)
self.parse_table('comptesTitres', Account.TYPE_MARKET)
self.parse_table('comptesVie', Account.TYPE_DEPOSIT)
self.parse_table('comptesRetraireEuros')
def get_accounts_list(self):
return self.accounts.itervalues()
def parse_table(self, what, actype=Account.TYPE_UNKNOWN):
tables = self.document.xpath("//table[@id='%s']" % what, smart_strings=False)
if len(tables) < 1:
return
lines = tables[0].xpath(".//tbody/tr")
for line in lines:
account = Account()
tmp = line.xpath("./td//a")[0]
account.label = to_unicode(tmp.text)
account.type = actype
account._link_id = tmp.get("href")
if 'BourseEnLigne' in account._link_id:
account.type = Account.TYPE_MARKET
tmp = line.xpath("./td/span/strong")
if len(tmp) >= 2:
tmp_id = tmp[0].text
tmp_balance = tmp[1].text
else:
tmp_id = line.xpath("./td//span")[1].text
tmp_balance = tmp[0].text
account.id = tmp_id
account.currency = account.get_currency(tmp_balance)
account.balance = Decimal(FrenchTransaction.clean_amount(tmp_balance))
if account.id in self.accounts:
a = self.accounts[account.id]
a._card_links.append(account._link_id)
if not a.coming:
a.coming = Decimal('0.0')
a.coming += account.balance
else:
account._card_links = []
self.accounts[account.id] = account
page = self.browser.get_page(self.browser.openurl(self.browser.buildurl('/voscomptes/canalXHTML/comptesCommun/imprimerRIB/init-imprimer_rib.ea', ('compte.numero', account.id))))
account.iban = page.get_iban()
def get_account(self, id):
try:
return self.accounts[id]
except KeyError:
raise AccountNotFound('Unable to find account: %s' % id)
示例10: on_loaded
def on_loaded(self):
if self.document.xpath(u'//h2[text()="%s"]' % u'ERREUR'):
raise BrowserUnavailable()
self.accounts = OrderedDict()
self.parse_table('comptes', Account.TYPE_CHECKING)
self.parse_table('comptesEpargne', Account.TYPE_SAVINGS)
self.parse_table('comptesTitres', Account.TYPE_MARKET)
self.parse_table('comptesVie', Account.TYPE_DEPOSIT)
self.parse_table('comptesRetraireEuros')
示例11: get_list
def get_list(self):
accounts = OrderedDict()
for tr in self.document.getiterator('tr'):
first_td = tr.getchildren()[0]
if (first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g') \
and first_td.find('a') is not None:
a = first_td.find('a')
link = a.get('href', '')
if link.startswith('POR_SyntheseLst'):
continue
url = urlparse(link)
p = parse_qs(url.query)
if not 'rib' in p:
continue
for i in (2,1):
balance = FrenchTransaction.clean_amount(tr.getchildren()[i].text.strip(' EUR'))
if len(balance) > 0:
break
balance = Decimal(balance)
id = p['rib'][0]
if id in accounts:
account = accounts[id]
if not account.coming:
account.coming = Decimal('0.0')
account.coming += balance
account._card_links.append(link)
continue
account = Account()
account.id = id
account.label = unicode(a.text).strip().lstrip(' 0123456789').title()
account._link_id = link
account._card_links = []
account.balance = balance
accounts[account.id] = account
return accounts.itervalues()
示例12: on_loaded
def on_loaded(self):
for script in self.document.xpath('//script'):
text = script.text
if text is None:
continue
m = re.search("window.location.replace\('([^']+)'\);", text)
if m:
self.browser.location(m.group(1))
try:
self.browser.select_form(name='banque')
except FormNotFoundError:
pass
else:
self.browser.set_all_readonly(False)
accounts = OrderedDict()
for tr in self.document.getroot().cssselect('table.compteTable > tbody > tr'):
if len(tr.findall('td')) == 0:
continue
attr = tr.xpath('.//a')[0].attrib.get('onclick', '')
m = re.search("value = '(\w+)';(checkAndSubmit\('\w+','(\w+)','(\w+)'\))?", attr)
if m:
typeCompte = m.group(1)
tagName = m.group(3)
if tagName is not None:
value = self.document.xpath('//input[@name="%s"]' % m.group(3))[int(m.group(4))].attrib['value']
else:
value = typeCompte
accounts[value] = (typeCompte, tagName)
try:
typeCompte, tagName = accounts[self.browser.accnum]
value = self.browser.accnum
except KeyError:
accnums = ', '.join(accounts.keys())
if self.browser.accnum != '00000000000':
self.logger.warning(u'Unable to find account "%s". Available ones: %s' % (self.browser.accnum, accnums))
elif len(accounts) > 1:
self.logger.warning('There are several accounts, please use "accnum" backend parameter to force the one to use (%s)' % accnums)
value, (typeCompte, tagName) = accounts.popitem(last=False)
self.browser['typeCompte'] = typeCompte
if tagName is not None:
self.browser[tagName] = [value]
self.browser.submit()
示例13: AccountList
class AccountList(BasePage):
def on_loaded(self):
self.accounts = OrderedDict()
self.parse_table('comptes', Account.TYPE_CHECKING)
self.parse_table('comptesEpargne', Account.TYPE_SAVINGS)
self.parse_table('comptesTitres', Account.TYPE_MARKET)
self.parse_table('comptesVie', Account.TYPE_DEPOSIT)
self.parse_table('comptesRetraireEuros')
def get_accounts_list(self):
return self.accounts.itervalues()
def parse_table(self, what, actype=Account.TYPE_UNKNOWN):
tables = self.document.xpath("//table[@id='%s']" % what, smart_strings=False)
if len(tables) < 1:
return
lines = tables[0].xpath(".//tbody/tr")
for line in lines:
account = Account()
tmp = line.xpath("./td//a")[0]
account.label = to_unicode(tmp.text)
account.type = actype
account._link_id = tmp.get("href")
if 'BourseEnLigne' in account._link_id:
account.type = Account.TYPE_MARKET
tmp = line.xpath("./td/span/strong")
if len(tmp) >= 2:
tmp_id = tmp[0].text
tmp_balance = tmp[1].text
else:
tmp_id = line.xpath("./td//span")[1].text
tmp_balance = tmp[0].text
account.id = tmp_id
account.currency = account.get_currency(tmp_balance)
account.balance = Decimal(FrenchTransaction.clean_amount(tmp_balance))
if account.id in self.accounts:
a = self.accounts[account.id]
a._card_links.append(account._link_id)
if not a.coming:
a.coming = Decimal('0.0')
a.coming += account.balance
else:
account._card_links = []
self.accounts[account.id] = account
def get_account(self, id):
try:
return self.accounts[id]
except KeyError:
raise AccountNotFound('Unable to find account: %s' % id)
示例14: __init__
def __init__(self, name, backend):
self.my_id = backend.browser.get_userid()
self.name = 'wiki/weboob/%s' % name
self.description = None
self.date = None
self.begin = None
self.end = None
self.location = None
self.winner = None
self.backend = backend
self.members = OrderedDict()
self.load()
示例15: parse_profile
def parse_profile(self, profile, consts):
if profile['online']:
self.status = Contact.STATUS_ONLINE
self.status_msg = u'online'
self.status_msg = u'since %s' % profile['last_cnx']
else:
self.status = Contact.STATUS_OFFLINE
self.status_msg = u'last connection %s' % profile['last_cnx']
self.summary = html2text(profile.get('announce', '')).strip().replace('\n\n', '\n')
if len(profile.get('shopping_list', '')) > 0:
self.summary += u'\n\nLooking for:\n%s' % html2text(profile['shopping_list']).strip().replace('\n\n', '\n')
for photo in profile['pics']:
self.set_photo(photo.split('/')[-1],
url=photo + '/full',
thumbnail_url=photo + '/small',
hidden=False)
self.profile = OrderedDict()
if 'sex' in profile:
for section, d in self.TABLE.iteritems():
flags = ProfileNode.SECTION
if section.startswith('_'):
flags |= ProfileNode.HEAD
if (section.startswith('+') and int(profile['sex']) != 1) or \
(section.startswith('-') and int(profile['sex']) != 0):
continue
section = section.lstrip('_+-')
s = ProfileNode(section, section.capitalize(), OrderedDict(), flags=flags)
for key, builder in d.iteritems():
try:
value = builder.get_value(profile, consts[int(profile['sex'])])
except KeyError:
pass
else:
s.value[key] = ProfileNode(key, key.capitalize().replace('_', ' '), value)
self.profile[section] = s
self._aum_profile = profile