2024-06-07 12:15:48 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
|
|
|
|
|
|
def aqi_data(session):
|
|
|
|
query2 = text('''
|
|
|
|
SELECT city_name,aqi,sqiText
|
|
|
|
FROM aqi_now_analyse''')
|
|
|
|
data = session.execute(query2).fetchall()
|
|
|
|
data1 = []
|
|
|
|
for idx, row in enumerate(data):
|
|
|
|
data1.append(
|
|
|
|
{
|
|
|
|
"name": row[0],
|
2024-06-07 12:54:53 +00:00
|
|
|
"value": [[idx + 1, float(row[1]), row[2]]],
|
2024-06-07 12:15:48 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
# Serialize the list of dictionaries to JSON
|
|
|
|
data = json.dumps(data1, ensure_ascii=False, indent=4)
|
|
|
|
|
|
|
|
# 将 JSON 数据写入 JavaScript 文件
|
|
|
|
with open('data.js', 'a', encoding='utf-8') as js_file:
|
|
|
|
js_file.write('const Chart6_Data = ')
|
|
|
|
js_file.write(data)
|
|
|
|
js_file.write("\n\n")
|