# -*- coding: utf-8 -*-
# @Time : 2018/11/18 10:41 PM
# @Author : cxa
# @File : motordb.py
# @Software: PyCharm
import asyncio try:
import uvloop asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except ImportError:
pass from motor.motor_asyncio import AsyncIOMotorClient
from pymongo import UpdateOne class MotorBase:
_db = {}
_collection = {} def __init__(self, loop=None):
self.motor_uri = ''
self.loop = loop or asyncio.get_event_loop() def client(self, db):
self.motor_uri = f"mongodb://localhost:27017/{db}"
return AsyncIOMotorClient(self.motor_uri, io_loop=self.loop) def get_db(self, db='test'):
if db not in self._db:
self._db[db] = self.client(db)[db] return self._db[db] async def savedata():
mb = MotorBase().get_db('test')
await mb.news.insert_one({'name': "lisa"}) async def save_data(items, col="demo", key="obj_id"):
"""
:param items:
:param col:
:param key:
:return:
"""
# storage.info(f"此时的items:{items}")
# UpdateOne
mb = MotorBase().get_db("aio_spider_data")
if isinstance(items, list):
requests = list()
r_a = requests.append
for item in items:
try:
r_a(UpdateOne({
key: item.get(key)},
{'$set': item},
upsert=True))
except Exception as e:
storage.error(f"数据插入出错:{e.args}此时的item是:{item}")
await mb[col].bulk_write(requests, ordered=False, bypass_document_validation=True) if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(savedata())

motor的使用的更多相关文章

  1. Arduino 各种模块篇 motor shield

    根据arduino官方网站出的shield, 类似的情况有很多中motor shield 这里测试采用的是http://www.seeedstudio.com/wiki/Motor_Shield_V1 ...

  2. motor和servo

    程序简单易读,不再做注释 motor.py from gpiozero import Motor from gpiozero import LED led = LED(2) motor = Motor ...

  3. motor helper

    # -*- coding: utf-8 -*- # @Time : 2019-02-13 10:44 # @Author : cxa # @File : mongohelper.py # @Softw ...

  4. Tornado 中 PyMongo Motor MongoEngine 的性能测试

    最近在使用 Tornado 开发 API,数据库选择了 MongoDB,因为想使用 Geo 搜索的特性.Python 可供选择的 MongoDB Drivers 可以在官网查找. 在这些 Driver ...

  5. AVR446_Linear speed control of stepper motor步进电机曲线分析

    1.1.  单片机代码处理 // 定义定时器预分频,定时器实际时钟频率为:72MHz/(STEPMOTOR_TIMx_PRESCALER+1) #define STEPMOTOR_TIM_PRESCA ...

  6. Electric Motor Manufacturer - Motor Protection: 5 Questions, 5 Answers

    I. Selection principle of motor protectorThe  Electric Motor Manufacturer   stated that the reasonab ...

  7. Eaton Char-Lynn Motor : Performance Of Small Displacement Motors

    The small-displacement supercharged motor replaces the large-displacement motor with the speed of li ...

  8. Cycloid Hydraulic Motor Use: Use Failure And Treatment

    The cycloidal hydraulic motor is a small low-speed, high-torque hydraulic motor with a shaft-distrib ...

  9. Low Speed High Torque Hydraulic Motor: Motion Performance

    Crank connecting rod type low speed high torque hydraulic motor is used earlier, which is called Sta ...

随机推荐

  1. Persits.Jpeg CMYK-to-RGB

    这几天发现有几个用户上传的图片显示一个“红叉叉”,用迅雷下载一看,原来图片的“模式”是CMYK,这样的模式是不能在IE中正常显示的. 我想起能不能用程序自动转换呢? 在网上看到利用Persits.Jp ...

  2. Linux查看端口、进程信息

    1.linux上如何查看端口 通常情况下,某个端口号会被莫名其妙的占用了.却不知道什么东东占用了,影响心情.通过如下命令,即可查看某一个端口号是否被占用 1)lsof -i:端口号,即可查看某一端口的 ...

  3. 二叉查找树(BST)、平衡二叉树(AVL树)

    二叉查找树(BST) 特殊的二叉树,又称为排序二叉树.二叉搜索树.二叉排序树. 二叉查找树实际上是数据域有序的二叉树,即对树上的每个结点,都满足其左子树上所有结点的数据域均小于或等于根结点的数据域,右 ...

  4. 任意输入一串字符串,求该字符串中字符的出现次数并打印出来,如输入“bcaba”输出:b 2 c 1 a 2

    前言:其实我还是有点不懂,有点郁闷了,算了直接把代码放上去把. 方法一: Scanner input=new Scanner(System.in); System.out.println(" ...

  5. 内置窗口 pyqt5

    1.使用Qt Designer设计三个窗口 注意:在主窗口中需要添加一个girdLayout 2.创建**.py from PyQt5.QtWidgets import QMainWindow, QA ...

  6. SDRAM学习笔记(二)

    上一篇博客主要讲解了一下SDRAM整体结构以及PCB方面的注意事项.接下来讲解一下需要用到的一些命令. 1.常用命令的缩写 上述是常用到的一些指令集. 2.模式寄存器   (1)突发长度 通过对A0~ ...

  7. GoLang基础数据类型-切片(slice)详解

    GoLang基础数据类型-切片(slice)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 数组的长度在定义之后无法再次修改:数组是值类型,每次传递都将产生一份副本.显然这种数 ...

  8. Neural Networks and Deep Learning 课程笔记(第三周)浅层神经网络(Shallow neural networks)

    3.1 神经网络概述(Neural Network Overview ) (神经网络中,我们要反复计算a和z,最终得到最后的loss function) 3.2 神经网络的表示(Neural Netw ...

  9. WebMvcConfigurerAdapter已过时,替换接口或类

    WebMvcConfigurerAdapter已经过时,在新版本2.x中被废弃,原因是springboot2.0以后,引用的是spring5.0,而spring5.0取消了WebMvcConfigur ...

  10. 一步一步配置 Dell OME 监控 Dell 服务器硬件报警

    本文包括以下四个部分: 下载 Dell OME 安装 Dell OME 配置 Dell OME 配置 iDRAC 下载 Dell OME 以Dell PowerEdge R730xd 为例 1.登录 ...