Пример #1
0
def storage_mysql():
    # 获取所有数据
    gzbd_all_data = gzbd.gzbd_spider.gzbd_all_data()

    for item in gzbd_all_data:
        epidemic_date = item["日期"]
        # build sql语句:根据时间查询,插入语句
        query_sql = "select * from gzbd_epidemic where date = %s" % (
            epidemic_date, )
        insert_sql = "insert into gzbd_epidemic (region, date, diagnosis, overseas_import, cure, " \
                     "death, therapy, observation) values ('%s', '%s', %s, %s, %s, %s, %s, %s)" % \
                     (item["地区"], item["日期"], item.get("确诊数", None), item.get("境外输入数", None), item.get("治愈数", None),
                      item.get("死亡数", None), item.get("隔离数", None), item.get("观察数", None))
        insert_sql = insert_sql.replace("None", "Null")
        print(insert_sql)
        # 查询数据,判断是否需要插入
        conn, cur = mysql_util.get_connect_cursor()
        result = mysql_util.execute_(query_sql)
        if len(result) == 0:
            # 插入数据
            result = mysql_util.execute_(insert_sql)
            if result > 0:
                print("ok")
            else:
                print("error")
Пример #2
0
def query_resource():  # 重构 单查询
    conn, cur = mysql_util.get_connect_cursor()
    # 获取连接器、游标
    sql = "select * from user"
    result = mysql_util.execute_query(cur, sql)
    # 执行
    print(result)
    # mysql_util.commit_(conn);  # 提交
    mysql_util.close_connect_cursor(conn, cur)
Пример #3
0
def inset_resource():
    conn, cur = mysql_util.get_connect_cursor()
    #获取连接器、游标
    sql = "insert into resource (resource_uri, resource_name, permission) values ('www','wang2', '/baidu')"
    mysql_util.execute_insert_update_delete(cur, sql)
    #执行
    mysql_util.commit_(conn)
    #提交
    mysql_util.close_connect_cursor(conn, cur)
Пример #4
0
def query_resource():
    conn, cur = mysql_util.get_connect_cursor()
    sql = "select * from resource"
    result = mysql_util.execute_query(cur, sql)
    print(result)
    mysql_util.close_connect_cursor(conn, cur)
Пример #5
0
def inset_resource():
    conn, cur = mysql_util.get_connect_cursor()
    sql = "insert into resource (resource_uri, resource_name, permission) values ('aa', 'bb', 'cc')"
    mysql_util.execute_insert_update_delete(cur, sql)
    mysql_util.commit_(conn)
    mysql_util.close_connect_cursor(conn, cur)
Пример #6
0
def inser_resource():
    conn, cur = mysql_util.get_connect_cursor("test")
    sql = "insert into money(name,money) values('wangliu',2000)"
    mysql_util.execute_insert_update_delete(cur, sql)
    mysql_util.execute_commit(conn)
    mysql_util.execute_close(conn, cur)
Пример #7
0
def query_resource():
    conn, cur = mysql_util.get_connect_cursor("test")
    sql = "select * from money"
    result = mysql_util.execute_query(cur, sql)
    print(result)
    mysql_util.execute_close(conn, cur)