• json 脚本入库的几种方法


    json 脚本入库的几种方法,见代码:

    #-*- encoding: utf-8 -*-
    #第一种mongodb入库
    # from pymongo import *
    # import json
    # conn = MongoClient('127.0.0.1',27017)
    # db = conn.p2p
    # content = open('static/data/text.json','r',encoding='utf-8',errors='ignore')
    # data = json.load(content)
    # db.order.insert(data)
    # print(db.order.count())

    # 第二种SQLALCHEMY入库mysql
    # import json
    # from flask import Flask
    # from flask_sqlalchemy import SQLAlchemy
    # app = Flask(__name__)
    # app.config.from_pyfile("config.ini")
    # db = SQLAlchemy(app)
    # class Product(db.Model):
    # __tablename__= 'product'
    # id = db.Column(db.Integer,primary_key=True)
    # name = db.Column(db.String(200))
    # price = db.Column(db.Integer)
    # @app.route("/")
    # def index():
    # content = open('static/data/test.json','r',encoding='utf-8',errors='ignore')
    # data = json.load(content)

    # for i in data:
    # ret = Product(name=i['name'],price = i['price'])
    # db.session.add(ret)
    # return "入库成功"
    # if __name__ == "__main__":
    # app.run()

    #第三种 原生sql 入库mysql
    # import json
    # from pymysql import *
    # conn = connect(host="127.0.0.1",port=3306,user='root',password='mysql',database="myflask",charset="utf8")
    # cur = conn.cursor()
    # content = open('static/data/text.json','r',encoding='utf-8',errors='ignore')
    # data = json.load(content)
    # for i in data:
    # cur.execute("insert into order values(0,'"+i['name']+"','"+i['price']+"')")
    # conn.commit
  • 相关阅读:
    Java虚拟机平台无关性
    全局变量维护
    linux free 打印机
    存储介质
    Linux 从手表到大型主机 硬件驱动
    queue_action
    queue — A synchronized queue class
    Spark Shuffle 中 JVM 内存使用及配置内幕详情
    JAVA中Stack和Heap的区别
    spark 33G表
  • 原文地址:https://www.cnblogs.com/xcsg/p/10256635.html
Copyright © 2020-2023  润新知