# -*- 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. 神奇的操作——线段树合并(例题: BZOJ2212)

    什么是线段树合并? 首先你需要动态开点的线段树.(对每个节点维护左儿子.右儿子.存储的数据,然后要修改某儿子所在的区间中的数据的时候再创建该节点.) 考虑这样一个问题: 你现在有两棵权值线段树(大概是 ...

  2. Activity的跳转与传值

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://android.blog.51cto.com/268543/323982 Acti ...

  3. 【模板】堆优化Dijkstra

    Dij的核心思想:全局最小值不会被其他节点更新,因此得到最小值后只需要扩展一次即可. 概念:扩展.出队 注意:vis[ ]数组表示的是每个节点是否扩展过,因此开始时vis[st]不置1. 时间复杂度\ ...

  4. gcc-linaro-arm-linux-gnueabihf交叉编译器配置

    系统Ubuntu14.04 版本:gcc 版本 4.7.3 20130328 (prerelease) (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 ...

  5. OpenCV 无法启动此程序,因为计算机中丢失opencv_core249.dll。请尝试重新安装改程序已解决此问题

    换了64位的系统,配置好之后运行之前的程序,竟然给我抛出这个错误.应该是我的opencv没有安装对吧.系统报错 无法启动此程序,因为计算机中丢失opencv_core249.dll.请尝试重新安装改程 ...

  6. ArrayList创建步骤及基本方法

    ArrayList创建变量的步骤 ArrayList ------>集合 1: 导入包 java.util.ArrayList包中 2: 创建引用类型的变量 数据类型< 集合存储的数据类型 ...

  7. 牛客多校第三场 A- PACM Team 背包/记忆路径

    https://www.nowcoder.com/acm/contest/141#question 一眼背包,用四维dp记录在A,B,C,D条件限制下可以获得的最大知识点,但是题目要求输出路径,在输入 ...

  8. selenium批量翻译

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  9. python中迭代器和生成器的区别

    #!/usr/bin/python def power(values): for value in values: print "powing %s" % value yield ...

  10. Redis 安全配置

    1.禁止一些高危命令 修改 redis.conf 文件,添加 rename-command FLUSHALL "" rename-command FLUSHDB "&qu ...