console_pipeline.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2021/3/18 12:39 上午
  4. ---------
  5. @summary:
  6. ---------
  7. @author: Boris
  8. @email: boris_liu@foxmail.com
  9. """
  10. from feapder.pipelines import BasePipeline
  11. from typing import Dict, List, Tuple
  12. class ConsolePipeline(BasePipeline):
  13. """
  14. pipeline 是单线程的,批量保存数据的操作,不建议在这里写网络请求代码,如下载图片等
  15. """
  16. def save_items(self, table, items: List[Dict]) -> bool:
  17. """
  18. 保存数据
  19. Args:
  20. table: 表名
  21. items: 数据,[{},{},...]
  22. Returns: 是否保存成功 True / False
  23. 若False,不会将本批数据入到去重库,以便再次入库
  24. """
  25. return True
  26. def update_items(self, table, items: List[Dict], update_keys=Tuple) -> bool:
  27. """
  28. 更新数据
  29. Args:
  30. table: 表名
  31. items: 数据,[{},{},...]
  32. update_keys: 更新的字段, 如 ("title", "publish_time")
  33. Returns: 是否更新成功 True / False
  34. 若False,不会将本批数据入到去重库,以便再次入库
  35. """
  36. return True