#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

import akshare as ak
import mysql_database

print(ak.__version__)

# 实时行情数据
# 接口: stock_zh_a_spot
# 目标地址: http://vip.stock.finance.sina.com.cn/mkt/#hs_a
# 描述: A 股数据是从新浪财经获取的数据, 重复运行本函数会被新浪暂时封 IP, 建议增加时间间隔
# 限量: 单次返回所有 A 股上市公司的实时行情数据

stock_zh_a_spot_df = ak.stock_zh_a_spot_em()
# stock_zh_a_spot_df = ak.stock_zh_a_spot()
print(stock_zh_a_spot_df)

# 第三列'最新价' 没数据的行 删掉
stock_zh_a_spot_df = stock_zh_a_spot_df.dropna(subset=['最新价'])

# 保存成txt
stock_zh_a_spot_df.to_csv("stock_zh_a_spot.txt", sep="\t", index=False, encoding="utf-8")

mysql_database.insert_db(stock_zh_a_spot_df, "stock_zh_a_spot", True, "`代码`")
