本文整理汇总了Python中mptracker.patcher.TablePatcher.update方法的典型用法代码示例。如果您正苦于以下问题:Python TablePatcher.update方法的具体用法?Python TablePatcher.update怎么用?Python TablePatcher.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mptracker.patcher.TablePatcher
的用法示例。
在下文中一共展示了TablePatcher.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: committee_summaries
# 需要导入模块: from mptracker.patcher import TablePatcher [as 别名]
# 或者: from mptracker.patcher.TablePatcher import update [as 别名]
def committee_summaries(year=2014):
from mptracker.scraper.committee_summaries import SummaryScraper
patcher = TablePatcher(models.CommitteeSummary,
models.db.session,
key_columns=['pdf_url'])
summary_scraper = SummaryScraper(get_cached_session(),
get_cached_session('question-pdf'))
records = summary_scraper.fetch_summaries(year, get_pdf_text=True)
patcher.update(records)
models.db.session.commit()
示例2: load
# 需要导入模块: from mptracker.patcher import TablePatcher [as 别名]
# 或者: from mptracker.patcher.TablePatcher import update [as 别名]
def load(name, include_columns=None, create=True, remove=False,
_file=sys.stdin):
from mptracker.patcher import TablePatcher
if include_columns:
include_columns = set(include_columns.split(','))
def filter_record(r):
return {k: r[k] for k in r if k in include_columns}
else:
filter_record = lambda r: r
loader = TableLoader(name)
patcher = TablePatcher(loader.model, db.session, key_columns=['id'])
records = (filter_record(loader.decode_dict(flask.json.loads(line)))
for line in _file)
patcher.update(records, create=create, remove=remove)
db.session.commit()
示例3: test_remove_extra_records_honors_filter
# 需要导入模块: from mptracker.patcher import TablePatcher [as 别名]
# 或者: from mptracker.patcher.TablePatcher import update [as 别名]
def test_remove_extra_records_honors_filter(db_app):
records = [{'code': 'an', 'number': 1, 'name': "Anne"},
{'code': 'bo', 'number': 1, 'name': "Bob"},
{'code': 'cl', 'number': 2, 'name': "Claire"},
{'code': 'da', 'number': 2, 'name': "Dan"}]
from mptracker.patcher import TablePatcher
filter_patcher = TablePatcher(
Thing,
db.session,
key_columns=['code'],
filter={'number': 1},
)
filter_patcher.update(records)
filter_patcher.update(records[:1], remove=True)
assert sorted([t.name for t in Thing.query]) == ["Anne", "Claire", "Dan"]