示例#1
0
 def test_import_csv(self):
     mysql = db.Mysql()
     csv_path = "/dataset/origin.csv"
     mysql.create_table(csv_path, "test_db")
     mysql.import_csv(csv_path, "test_db")
     self.assertNotEqual(len(mysql.exec_sql("SELECT count(*) from test_db limit 10;")), 0)
     self.assertFalse(mysql.exec_sql("drop table test_db"))
示例#2
0
 def test_edge_cases(self):
     mysql = db.Mysql()
     self.assertFalse(mysql.exec_sql(None))
     self.assertTrue("error" in mysql.exec_sql("dasdwda"))
     self.assertFalse(mysql.create_table("", ""))
     self.assertFalse(mysql.create_table(None, None))
     self.assertFalse(mysql.import_csv("", ""))
     self.assertFalse(mysql.import_csv(None, None))
示例#3
0
def saveInfo(info, content):
    """
        作用:保存用户数据和帖子数据到数据库
        info:用户数据字典
        content:帖子数据
    """
    # print(content)
    mysql = db.Mysql()
    saveContent(mysql, content)
    saveUser(mysql, info)
    mysql.end()
示例#4
0
def realCalibration(CP):
    src_db = db.Mysql()
    src_db.open_session()

    normalValue = do_calibration(src_db, CP)
    print "Normal Calibration Value ---> : ", normalValue 

    if normalValue != None:
        svmValue = do_svm(src_db, normalValue, CP)
        print "Svm Calibration Value ===> : ", svmValue

    src_db.close_session()
示例#5
0
文件: test2.py 项目: luozhenhua/arts
def main():
    # test for db.py
    db1 = db.Mysql()
    db1.connect()
    db1.query()
    db1.disconnect()

    # test for sql.py
    sql1 = sql.Mysql()
    res = sql1.query(sql.Testtb1, 'id', 1)
    print(res)

    names = ("apple", "banana", "orange")
    name = random.choice(names)
    print("the random choice is %s" % name)
    res.name = name
    sql1.session.commit()
    res = sql1.query(sql.Testtb1, 'id', 1)
    print(res)

    items = sql1.queryall(sql.Testtb1)
    for res in items:
        print(res)
    sql1.queryall()
示例#6
0
import db
from log import Log

db_mysql = db.Mysql()


async def like(uid, oid):
    '''
    对一个对象(一条feed、文章、或者url)进行 like 操作,禁止 like 两次,第二次 like 返回错误码
    :param uid:用户ID
    :param oid:对象ID
    :return:
    '''
    connnetct = await db_mysql.conn()
    async with connnetct as conn:
        async with conn.cursor() as cur:
            uids = []   # 列表:存放所有的uid
            like_list = []  # 列表:存放oid所有的like用户
            # 查询like oid的所有uid
            await cur.execute("select uid from favour where oid = {}".format(oid))
            uids_ret = await cur.fetchall()
            for _ in uids_ret:
                uids.append(_[0])   # 将查询的结果存到列表里

            # 如果对象没有被like过,则往favour表插入用户
            if uid not in uids:
                await cur.execute("insert into favour values ('{}', '{}')".format(oid, uid))
                uids.append(uid)

                # 查询每个uid的uname
                for each_uid in uids:
示例#7
0
    return ret

def realCalibration(CP):
    src_db = db.Mysql()
    src_db.open_session()

    normalValue = do_calibration(src_db, CP)
    print "Normal Calibration Value ---> : ", normalValue 

    if normalValue != None:
        svmValue = do_svm(src_db, normalValue, CP)
        print "Svm Calibration Value ===> : ", svmValue

    src_db.close_session()


if __name__ == "__main__":
    src_db = db.Mysql()
    src_db.open_session()

    ap4vt_list = example.get_example_ap(src_db)
    for onetime_aplist in ap4vt_list:
        #calibration_value = do_calibration(src_db, onetime_aplist)
        #print "Src value : ", onetime_aplist[0][0], " <=========> ", "Calibration value : ", calibration_value 
        print "Src value : ", onetime_aplist[0][0] 
	realCalibration(onetime_aplist)

    src_db.close_session()


示例#8
0
 def test_connection(self):
     mysql = db.Mysql()
     self.assertIsNotNone(mysql)
     self.assertIsNotNone(mysql.connection)
示例#9
0
 def test_generate_table_exec_sql(self):
     mysql = db.Mysql()
     csv_path = "/dataset/origin.csv"
     mysql.create_table(csv_path, "test_db")
     self.assertTrue(("test_db",) in mysql.exec_sql("show tables"))
     self.assertFalse(mysql.exec_sql("drop table test_db"))
示例#10
0
 def test_exec_sql(self):
     mysql = db.Mysql()
     self.assertTrue(mysql.exec_sql("show databases"))
     self.assertTrue(mysql.exec_sql("show tables"))
示例#11
0
 def __init__(self):
     logger.info('|--------------------------|')
     logger.info('|---picrek-scrap started---|')
     logger.info('|--------------------------|')
     self.conf = config.Config()
     self.mdb = db.Mysql()