motor的使用
# -*- 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的使用的更多相关文章
- Arduino 各种模块篇 motor shield
根据arduino官方网站出的shield, 类似的情况有很多中motor shield 这里测试采用的是http://www.seeedstudio.com/wiki/Motor_Shield_V1 ...
- motor和servo
程序简单易读,不再做注释 motor.py from gpiozero import Motor from gpiozero import LED led = LED(2) motor = Motor ...
- motor helper
# -*- coding: utf-8 -*- # @Time : 2019-02-13 10:44 # @Author : cxa # @File : mongohelper.py # @Softw ...
- Tornado 中 PyMongo Motor MongoEngine 的性能测试
最近在使用 Tornado 开发 API,数据库选择了 MongoDB,因为想使用 Geo 搜索的特性.Python 可供选择的 MongoDB Drivers 可以在官网查找. 在这些 Driver ...
- AVR446_Linear speed control of stepper motor步进电机曲线分析
1.1. 单片机代码处理 // 定义定时器预分频,定时器实际时钟频率为:72MHz/(STEPMOTOR_TIMx_PRESCALER+1) #define STEPMOTOR_TIM_PRESCA ...
- Electric Motor Manufacturer - Motor Protection: 5 Questions, 5 Answers
I. Selection principle of motor protectorThe Electric Motor Manufacturer stated that the reasonab ...
- Eaton Char-Lynn Motor : Performance Of Small Displacement Motors
The small-displacement supercharged motor replaces the large-displacement motor with the speed of li ...
- 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 ...
- 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 ...
随机推荐
- hdu4549_M斐波那契数列 解题报告
Solution: 1.快速幂:数/矩阵 2.以证明1000000007是素数. 费马小定理: 若p是素数,gcd(a,p)=1,则a^(p-1)1(mod p). 若a^b mod p 中b很大,则 ...
- SQL 运算符
运算符是一个保留字或字符,主要用于连接WHERE后面的条件. 一.算数运算符 运算符 描述 + 加法 把运算符两边的值相加 - 减法 左操作数减去右操作数 * 乘法 把运算符两边的值相乘 / 除法 左 ...
- hdu 2874(裸LCA)
传送门:Problem 2874 https://www.cnblogs.com/violet-acmer/p/9686774.html 改了一晚上bug,悲伤辣么大,明天再补详细题解 题解: 题目中 ...
- vue router.push(),router.replace(),router.go()
1.router.push(location)=====window.history.pushState 想要导航到不同的 URL,则使用 router.push 方法.这个方法会向 history ...
- springmvc 中@Controller和@RestController的区别
@Controller和@RestController的区别? 官方文档:@RestController is a stereotype annotation that combines @Respo ...
- go 包-锁机制
线程同步 import(“sync”) 互斥锁, var mu sync.Mutex 读写锁, var mu sync.RWMutex 资源竞争样例 func testMap() { var a ma ...
- Windows环境安装MySQL数据库
Windows环境安装MySQL数据库 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 最近在学习Java语言,开发环境在Windows操作系统上,因此需要在Windows上安装My ...
- tcpdump常用参数详解
tcpdump常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 好久没有更新我的博客了,看来自己最近还没有在放假中回过神来啊,哈哈~是不是也有小伙伴跟我一样呢?回归正题, ...
- OS + CentOS 7 / centos 7 / VirtualBox /vegrant
s VirtualBox:解决VirtualBox安装时libSDL-1.2.so.0()错误的问题. http://www.sklinux.com/983 为Centos6.2安装VirtualBo ...
- 关于Java形参和实参的理解
源码地址:https://github.com/mynawang/javabasic-summary/tree/master/chapter01 1.方法的形参中,java的基本数据类型是传值调用,对 ...