本文整理匯總了Python中weboob.tools.ordereddict.OrderedDict.iteritems方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.iteritems方法的具體用法?Python OrderedDict.iteritems怎麽用?Python OrderedDict.iteritems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weboob.tools.ordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.iteritems方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_profile
# 需要導入模塊: from weboob.tools.ordereddict import OrderedDict [as 別名]
# 或者: from weboob.tools.ordereddict.OrderedDict import iteritems [as 別名]
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
示例2: format
# 需要導入模塊: from weboob.tools.ordereddict import OrderedDict [as 別名]
# 或者: from weboob.tools.ordereddict.OrderedDict import iteritems [as 別名]
def format(self, obj, selected_fields=None, alias=None):
"""
Format an object to be human-readable.
An object has fields which can be selected.
:param obj: object to format
:type obj: BaseObject or dict
:param selected_fields: fields to display. If None, all fields are selected
:type selected_fields: tuple
:param alias: an alias to use instead of the object's ID
:type alias: unicode
"""
if isinstance(obj, BaseObject):
if selected_fields: # can be an empty list (nothing to do), or None (return all fields)
obj = obj.copy()
for name, value in obj.iter_fields():
if name not in selected_fields:
delattr(obj, name)
if self.MANDATORY_FIELDS:
missing_fields = set(self.MANDATORY_FIELDS) - set([name for name, value in obj.iter_fields()])
if missing_fields:
raise MandatoryFieldsNotFound(missing_fields)
formatted = self.format_obj(obj, alias)
else:
try:
obj = OrderedDict(obj)
except ValueError:
raise TypeError('Please give a BaseObject or a dict')
if selected_fields:
obj = obj.copy()
for name, value in obj.iteritems():
if name not in selected_fields:
obj.pop(name)
if self.MANDATORY_FIELDS:
missing_fields = set(self.MANDATORY_FIELDS) - set(obj.iterkeys())
if missing_fields:
raise MandatoryFieldsNotFound(missing_fields)
formatted = self.format_dict(obj)
if formatted:
self.output(formatted)
return formatted
示例3: registerEvent
# 需要導入模塊: from weboob.tools.ordereddict import OrderedDict [as 別名]
# 或者: from weboob.tools.ordereddict.OrderedDict import iteritems [as 別名]
def registerEvent(self):
selection = self.ui.modulesList.selectedItems()
if not selection:
return
try:
module = self.weboob.modules_loader.get_or_load_module(unicode(selection[0].text()).lower())
except ModuleLoadError:
module = None
if not module:
return
dialog = QDialog(self)
vbox = QVBoxLayout(dialog)
if module.website:
website = 'on the website <b>%s</b>' % module.website
else:
website = 'with the module <b>%s</b>' % module.name
vbox.addWidget(QLabel('To create an account %s, please provide this information:' % website))
formlayout = QFormLayout()
props_widgets = OrderedDict()
for key, prop in module.klass.ACCOUNT_REGISTER_PROPERTIES.iteritems():
widget = QtValue(prop)
formlayout.addRow(QLabel(u'%s:' % prop.label), widget)
props_widgets[prop.id] = widget
vbox.addLayout(formlayout)
buttonBox = QDialogButtonBox(dialog)
buttonBox.setStandardButtons(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
self.connect(buttonBox, SIGNAL("accepted()"), dialog.accept)
self.connect(buttonBox, SIGNAL("rejected()"), dialog.reject)
vbox.addWidget(buttonBox)
end = False
while not end:
end = True
if dialog.exec_():
account = Account()
account.properties = {}
for key, widget in props_widgets.iteritems():
try:
v = widget.get_value()
except ValueError as e:
QMessageBox.critical(self, self.tr('Invalid value'),
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (key, e))
end = False
break
else:
account.properties[key] = v
if end:
try:
module.klass.register_account(account)
except AccountRegisterError as e:
QMessageBox.critical(self, self.tr('Error during register'),
unicode(self.tr('Unable to register account %s:<br /><br />%s')) % (website, e))
end = False
else:
for key, value in account.properties.iteritems():
if key in self.config_widgets:
self.config_widgets[key][1].set_value(value)