lwzm
12/25/2015 - 3:10 AM

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])