42 lines
958 B
Python
42 lines
958 B
Python
import pymysql
|
|
import math
|
|
from util import config
|
|
# 获取一些数据库数据
|
|
|
|
|
|
# 通过sql语句获得数据库数据
|
|
def get_data_from_mysql(sql_query):
|
|
# 打开数据库连接
|
|
db = pymysql.connect(**config.db_config)
|
|
# 使用 cursor() 方法创建一个游标对象 cursor
|
|
cursor = db.cursor()
|
|
# 获取bots中的apps基本信息
|
|
try:
|
|
# 执行SQL语句
|
|
cursor.execute(sql_query)
|
|
# 获取所有记录列表
|
|
results = cursor.fetchall()
|
|
return results
|
|
except Exception as e:
|
|
# 如果发生错误则回滚
|
|
db.rollback()
|
|
print("get_bots_project_stars error:")
|
|
print(e)
|
|
|
|
# 打开数据库连接
|
|
db.close()
|
|
|
|
|
|
def tuple_to_list(tuple1):
|
|
list1 = []
|
|
for i in tuple1:
|
|
list1.append((i[0]))
|
|
return list1
|
|
|
|
|
|
def get_project_stars(sql_query):
|
|
return tuple_to_list(get_data_from_mysql(sql_query))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print(1) |