-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJiatou.py
183 lines (133 loc) · 3.24 KB
/
Jiatou.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# -*- coding:utf-8 -*-
import os
import time
from src.HK_data_miner import *
from src.util import *
from src.Tushare_adapter import *
from src.HK_data_processing import *
from src.Lixinger_adapter import *
from apscheduler.schedulers.background import BackgroundScheduler
def get_holding_data():
miner = HK_data_miner()
try:
#download
miner.get_holding_data()
miner.write_holding_data_mysqldb()
except Exception as e:
log(str(e))
pass
def get_detail_data():
miner = HK_data_miner()
try:
#download
miner.get_detail_data()
except Exception as e:
log(str(e))
pass
def update_basic_data():
Lxr_adapter = Lixinger_adapter()
try:
#update volume and amount information
Lxr_adapter.update_fundamental_info_history()
except Exception as e:
log(str(e))
pass
def update_holding_data():
data_proc = HK_data_processing()
try:
#update volume and amount information
data_proc.update_holding_detail()
data_proc.update_trend_history()
except Exception as e:
log(str(e))
pass
def update_basics():
ts_adatper = Tushare_adapter()
try:
ts_adatper.update_stock_basics()
except Exception as e:
log(str(e))
pass
def get_HK_amount_flow():
log('get_HK_amount_flow not implemented')
def get_HK_amount_top():
log('get_HK_amount_top not implemented')
def jiatou():
clear_log()
save_cookie('')
scheduleTask()
def scheduleTask():
sched = BackgroundScheduler()
#周一至周五对应 17点执行 更新数基本数据,每日执行一次
sched.add_job(
update_basics, 'cron',
hour='17',
minute='00',
day_of_week ='0-5',
timezone = 'Asia/Shanghai')
#周二至周六对应 5点执行 获取每日持仓数量情况,每日执行一次
sched.add_job(
get_holding_data, 'cron',
hour='05',
minute='00',
day_of_week ='1-6',
timezone = 'Asia/Shanghai')
#周二至周六对应 5点15分执行 获取每日持仓数量明细情况,每日执行一次
sched.add_job(
update_holding_data, 'cron',
hour='5',
minute='15',
day_of_week ='1-6',
timezone = 'Asia/Shanghai')
#LXR
'''
sched.add_job(
update_basic_data, 'cron',
hour='23',
minute='35',
timezone = 'Asia/Shanghai')
'''
'''
#周一至周五对应 日9点半至11点半,13点至15点,获取资金流入流出,每秒执行一次
sched.add_job(
get_HK_amount_flow, 'cron',
hour='09-15',
minute='0-59',
second = '0-59',
timezone = 'Asia/Shanghai')
#周一至周五对应 日5点40分,获取资金流入流出,,每秒执行一次
sched.add_job(
get_HK_amount_top, 'cron',
hour='5',
minute='40-45',
second = '0-59',
timezone = 'Asia/Shanghai')
'''
sched.start()
while True:
time.sleep(1)
def createDaemon():
# create - fork 1
try:
if os.fork() > 0:
os._exit(0)
except OSError as error:
log('fork #1 failed: %d (%s)' % (error.errno, error.strerror))
os._exit(1)
# it separates the son from the father
os.chdir('/root/Ares/') #todo: change to /
os.setsid()
os.umask(0)
# create - fork 2
try:
pid = os.fork()
if pid > 0:
log('Daemon PID %d' % pid)
os._exit(0)
except OSError as error:
log('fork #2 failed: %d (%s)' % (error.errno, error.strerror))
os._exit(1)
jiatou()
if __name__ == '__main__':
createDaemon()
#get_HK_detail_history()