forked from pythonstock/stock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily_job.py
49 lines (40 loc) · 1.38 KB
/
daily_job.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
import libs.common as common
import sys
import os
import time
import pandas as pd
import tushare as ts
from sqlalchemy.types import NVARCHAR
from sqlalchemy import inspect
import datetime
import shutil
####### 使用 5.pdf,先做 基本面数据 的数据,然后在做交易数据。
#
def stat_all(tmp_datetime):
datetime_str = (tmp_datetime).strftime("%Y-%m-%d")
datetime_int = (tmp_datetime).strftime("%Y%m%d")
cache_dir = common.bash_stock_tmp % (datetime_str[0:7], datetime_str)
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)
print("remove cache dir force :", cache_dir)
print("datetime_str:", datetime_str)
print("datetime_int:", datetime_int)
data = ts.top_list(datetime_str)
# 处理重复数据,保存最新一条数据。最后一步处理,否则concat有问题。
#
if not data is None and len(data) > 0:
# 插入数据库。
# del data["reason"]
data["date"] = datetime_int # 修改时间成为int类型。
data = data.drop_duplicates(subset="code", keep="last")
data.head(n=1)
common.insert_db(data, "ts_top_list", False, "`date`,`code`")
else:
print("no data .")
print(datetime_str)
# main函数入口
if __name__ == '__main__':
# 使用方法传递。
tmp_datetime = common.run_with_args(stat_all)