Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
R
robo-dividend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenwen.tang
robo-dividend
Commits
c862f571
Commit
c862f571
authored
Dec 30, 2024
by
吕先亚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update save json
parent
8ec40d32
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
0 deletions
+101
-0
config-mdis_prr3.yml
config-mdis_prr3.yml
+1
-0
note_updater.py
web/note_updater.py
+91
-0
robo_controller.py
web/robo_controller.py
+9
-0
No files found.
config-mdis_prr3.yml
View file @
c862f571
...
@@ -259,6 +259,7 @@ robo-executor: # 执行器相关
...
@@ -259,6 +259,7 @@ robo-executor: # 执行器相关
web
:
web
:
guid
:
AB088E61-FAB1-4466-B6AD-6E8AE253391E
guid
:
AB088E61-FAB1-4466-B6AD-6E8AE253391E
port
:
8080
port
:
8080
save-path
:
${EXPORT_PATH:json}
web/note_updater.py
0 → 100644
View file @
c862f571
import
glob
import
os
import
yaml
import
pymysql
from
py_jftech
import
get_project_path
import
pandas
as
pd
import
json
# 读取YAML配置文件
def
read_yaml_config
(
file_path
):
with
open
(
file_path
,
'r'
)
as
file
:
return
yaml
.
safe_load
(
file
)
# 连接到MySQL数据库
def
connect_to_mysql
(
config
):
try
:
# 使用MySQL配置连接数据库
connection
=
pymysql
.
connect
(
host
=
config
[
'host'
],
user
=
config
[
'user'
],
password
=
config
[
'password'
],
database
=
config
[
'database'
]
)
return
connection
except
Exception
as
e
:
print
(
f
"Error connecting to MySQL: {e}"
)
return
None
# 执行数据库操作
def
execute_db_operations
(
connection
,
sql
):
try
:
with
connection
.
cursor
()
as
cursor
:
# 执行数据库操作
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
print
(
result
)
finally
:
connection
.
close
()
def
read_excel_to_json
(
file_path_or_obj
):
"""
根据路径或文件对象读取Excel文件中的note_review工作表,并返回JSON格式的内容。
:param file_path_or_obj: Excel文件的路径或文件对象
:return: 包含note_review工作表内容的JSON字符串
"""
try
:
# 读取Excel文件中的note_review工作表
df
=
pd
.
read_excel
(
file_path_or_obj
,
sheet_name
=
'note_review'
)
# 将DataFrame转换为JSON格式
json_data
=
df
.
to_json
(
orient
=
'records'
,
force_ascii
=
False
)
return
json_data
except
Exception
as
e
:
print
(
f
"读取Excel文件时出错: {e}"
)
return
None
# 主函数
def
main
():
project_path
=
get_project_path
()
# 1.遍历project_path下面所有yml配置,保存到list(yml_paths)
yml_paths
=
glob
.
glob
(
os
.
path
.
join
(
project_path
,
'**'
,
'*.yml'
),
recursive
=
True
)
excel_path
=
os
.
path
.
join
(
project_path
,
'SV投資組合配置說明_1224v1.xlsx'
)
datas
=
json
.
loads
(
read_excel_to_json
(
excel_path
))
for
data
in
datas
:
rebalance_date
=
data
.
get
(
'rebalance_date'
)
guid
=
data
.
get
(
'portfolio_guid'
)
formal_review
=
data
.
get
(
'formal_review'
)
# 遍历yml_paths, 找到对应guid的yml文件,读取数据库相关配置,获取数据库连接
for
path
in
yml_paths
:
with
open
(
path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
config
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
if
config
.
get
(
'web'
):
if
config
[
'web'
][
'guid'
]
==
guid
:
print
(
f
"找到配置文件: {path}"
)
break
connection
=
connect_to_mysql
(
config
)
# todo 2.执行数据库操作,将formal_review更新到数据库中
sql
=
f
"UPDATE portfolio SET formal_review = '{formal_review}' WHERE guid = '{guid}'"
execute_db_operations
(
connection
,
sql
)
if
__name__
==
"__main__"
:
main
()
web/robo_controller.py
View file @
c862f571
...
@@ -39,6 +39,14 @@ async def send_email():
...
@@ -39,6 +39,14 @@ async def send_email():
sendmail
(
receives
=
receives
,
copies
=
copies
,
subject
=
subject
,
content
=
content
,
attach_paths
=
[
filepath
])
sendmail
(
receives
=
receives
,
copies
=
copies
,
subject
=
subject
,
content
=
content
,
attach_paths
=
[
filepath
])
async
def
save_json
():
if
get_config
(
'web.save-path'
):
recommends
=
await
recommend
()
filepath
=
os
.
path
.
join
(
os
.
path
.
abspath
(
get_config
(
'web.save-path'
)),
f
'{REC_GID}.json'
)
with
open
(
filepath
,
"w"
,
encoding
=
'utf-8'
)
as
file
:
json
.
dump
(
recommends
,
file
,
indent
=
4
,
ensure_ascii
=
False
)
def
get_today_rec
():
def
get_today_rec
():
from
portfolios.dao
import
robo_mpt_portfolios
as
rmp
from
portfolios.dao
import
robo_mpt_portfolios
as
rmp
from
api
import
PortfoliosType
,
PortfoliosRisk
from
api
import
PortfoliosType
,
PortfoliosRisk
...
@@ -129,6 +137,7 @@ async def startup_event():
...
@@ -129,6 +137,7 @@ async def startup_event():
if
current_time
.
time
()
>
target_time
:
if
current_time
.
time
()
>
target_time
:
scheduler
.
add_job
(
main
.
start
,
trigger
=
DateTrigger
(
run_date
=
current_time
))
scheduler
.
add_job
(
main
.
start
,
trigger
=
DateTrigger
(
run_date
=
current_time
))
# await send_email()
# await send_email()
await
save_json
()
# 开启定时任务,执行实盘
# 开启定时任务,执行实盘
scheduler
.
add_job
(
main
.
start
,
'cron'
,
day
=
1
,
hour
=
10
,
minute
=
25
)
scheduler
.
add_job
(
main
.
start
,
'cron'
,
day
=
1
,
hour
=
10
,
minute
=
25
)
scheduler
.
add_job
(
send_email
,
'cron'
,
day
=
1
,
hour
=
10
,
minute
=
25
)
scheduler
.
add_job
(
send_email
,
'cron'
,
day
=
1
,
hour
=
10
,
minute
=
25
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment