python sqlite_to_mongo.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python sqlite_to_mongo.py相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python3

import sqlite3
import sys

import pymongo

fields = "name,ip,mac,nas,dt".split(",")


def main(table):
    conn = sqlite3.connect("online_logs.db")
    mongo = pymongo.MongoClient("db-mongo")

    c = conn.cursor()
    m = mongo.TEST.online_logs  # TEST todo

    '''
    for row in c.execute("select name,ip,mac,nas,dt from {}".format(table)):
        m.insert_one(dict(zip(fields, row)))
    '''
    m.insert_many(
        dict(zip(fields, row))
        for row in c.execute("select name,ip,mac,nas,dt from {}".format(table))
    )
    
    
if __name__ == "__main__":
    main(sys.argv[1])

以上是关于python sqlite_to_mongo.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python