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
294dd165
Commit
294dd165
authored
Oct 31, 2022
by
jichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建
parent
e08c69f0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
45 deletions
+61
-45
main.py
main.py
+15
-3
__env_config.py
utils/__env_config.py
+13
-15
__init__.py
utils/__init__.py
+4
-8
__logger.py
utils/__logger.py
+8
-2
base.py
utils/base.py
+2
-5
date_utils.py
utils/date_utils.py
+2
-0
datebase.py
utils/datebase.py
+17
-12
No files found.
main.py
View file @
294dd165
from
utils
import
*
import
utils
as
ut
table
=
'robo_fund_info'
columns
=
'id, FT_Ticker, Lipper_ID, Name_CH, wind_ticker, Bloomberg_Ticker, FT_TW_RISK, RISK, ROBO, TEST, Asset, index_id'
@
read
def
getSyncFundInfos
():
return
f
"select {columns} from {table} where TEST = 1 or ROBO = 1 ;"
@
transaction
def
test
():
return
getSyncFundInfos
()
if
__name__
==
'__main__'
:
print
(
dir
())
print
(
dir
(
ut
))
print
(
test
())
utils/__env_config.py
View file @
294dd165
import
os
import
re
from
functools
import
partial
from
.base
import
*
...
...
@@ -71,24 +72,21 @@ def env_var_constructor(loader, node, raw=False):
return
value
if
raw
else
yaml
.
safe_load
(
value
)
def
_setup_yaml_parser
():
yaml
.
add_constructor
(
'!env_var'
,
env_var_constructor
,
yaml
.
SafeLoader
)
yaml
.
add_constructor
(
'!raw_env_var'
,
partial
(
env_var_constructor
,
raw
=
True
),
yaml
.
SafeLoader
)
yaml
.
add_implicit_resolver
(
'!env_var'
,
IMPLICIT_ENV_VAR_MATCHER
,
Loader
=
yaml
.
SafeLoader
)
def
_get_config
(
config_name
=
None
):
def
get_config
(
config_name
=
None
):
CONFIG_NAME
=
config_name
or
'config.yml'
path
=
f
'{get_project_path()}{os.path.sep}config.yml'
with
open
(
path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
return
yaml
.
safe_load
(
f
)
if
__name__
==
'__main__'
:
_get_config
()
yaml
.
add_constructor
(
'!env_var'
,
env_var_constructor
,
yaml
.
SafeLoader
)
yaml
.
add_constructor
(
'!raw_env_var'
,
partial
(
env_var_constructor
,
raw
=
True
),
yaml
.
SafeLoader
)
yaml
.
add_implicit_resolver
(
'!env_var'
,
IMPLICIT_ENV_VAR_MATCHER
,
Loader
=
yaml
.
SafeLoader
)
config
=
get_config
()
utils/__init__.py
View file @
294dd165
from
.date
import
*
from
.date
_utils
import
*
from
.base
import
*
from
.__env_config
import
_setup_yaml_parser
,
_get_config
from
.__logger
import
_setup_logger
_setup_yaml_parser
()
config
=
_get_config
()
if
'logger'
in
config
:
logger
=
_setup_logger
(
config
[
'logger'
])
from
.datebase
import
read
,
write
,
transaction
from
.__env_config
import
config
,
get_config
from
.__logger
import
build_logger
,
logger
utils/__logger.py
View file @
294dd165
import
os
from
logging
import
config
as
cf
,
getLogger
from
.base
import
*
from
.__env_config
import
config
from
.base
import
get_project_path
def
_setup
_logger
(
config
,
name
=
'base'
):
def
build
_logger
(
config
,
name
=
'base'
):
if
'handlers'
in
config
and
'file'
in
config
[
'handlers'
]:
file
=
config
[
'handlers'
][
'file'
]
path
=
os
.
path
.
join
(
get_project_path
(),
file
[
"filename"
])
...
...
@@ -11,3 +13,7 @@ def _setup_logger(config, name='base'):
cf
.
dictConfig
(
config
)
return
getLogger
(
name
)
if
'logger'
in
config
:
logger
=
build_logger
(
config
[
'logger'
])
utils/base.py
View file @
294dd165
import
os
__all__
=
[
'get_project_path'
,
'deep_dict_update'
]
def
get_project_path
():
for
anchor
in
[
'.idea'
,
'.git'
,
'config.yml'
,
'requirements.txt'
]:
...
...
@@ -27,8 +29,3 @@ def deep_dict_update(d1, d2):
for
key
in
d2
:
if
key
not
in
d1
:
d1
[
key
]
=
d2
[
key
]
if
__name__
==
'__main__'
:
print
(
get_project_path
())
# print(os.path.dirname('/123123/123123'))
utils/date.py
→
utils/date
_utils
.py
View file @
294dd165
import
calendar
from
datetime
import
timedelta
__all__
=
[
'filter_weekend'
,
'next_workday'
,
'is_workday'
]
def
filter_weekend
(
day
):
while
calendar
.
weekday
(
day
.
year
,
day
.
month
,
day
.
day
)
in
[
5
,
6
]:
...
...
utils/datebase.py
View file @
294dd165
...
...
@@ -2,12 +2,13 @@ import functools
import
pymysql
import
threading
from
pymysql.cursors
import
DictCursor
from
utils
import
config
from
.__env_config
import
config
as
default_config
from
functools
import
partial
class
Database
:
def
__init__
(
self
,
conf
=
None
):
self
.
config
=
conf
or
config
[
'database'
]
def
__init__
(
self
,
conf
ig
):
self
.
config
=
conf
ig
or
default_
config
[
'database'
]
def
__enter__
(
self
):
port
=
3306
...
...
@@ -34,9 +35,9 @@ class Database:
__local__
=
threading
.
local
()
def
read
(
func
=
None
,
one
=
False
):
def
read
(
func
=
None
,
config
=
None
,
one
=
False
):
if
func
is
None
:
return
functools
.
partial
(
read
,
one
=
one
)
return
functools
.
partial
(
read
,
config
=
config
,
one
=
one
)
def
execute
(
db
,
sql
):
db
.
cursor
.
execute
(
sql
)
...
...
@@ -52,14 +53,14 @@ def read(func=None, one=False):
if
hasattr
(
__local__
,
'db'
):
return
execute
(
__local__
.
db
,
sql
)
else
:
with
Database
()
as
db
:
with
Database
(
config
)
as
db
:
return
execute
(
db
,
sql
)
return
wraps
def
write
(
func
=
None
):
def
write
(
func
=
None
,
config
=
None
):
if
func
is
None
:
return
functools
.
partial
(
func
)
return
functools
.
partial
(
write
,
func
=
func
,
config
=
config
)
def
execute
(
db
,
sqls
):
if
isinstance
(
sqls
,
list
):
...
...
@@ -74,7 +75,7 @@ def write(func=None):
if
hasattr
(
__local__
,
'db'
):
execute
(
__local__
.
db
,
sqls
)
else
:
with
Database
()
as
db
:
with
Database
(
config
)
as
db
:
try
:
execute
(
db
,
sqls
)
db
.
connect
.
commit
()
...
...
@@ -84,15 +85,15 @@ def write(func=None):
return
wraps
def
transaction
(
func
=
None
):
def
transaction
(
func
=
None
,
config
=
None
):
if
func
is
None
:
return
functools
.
partial
(
func
)
return
functools
.
partial
(
transaction
,
func
=
func
,
config
=
config
)
@
functools
.
wraps
(
func
)
def
wraps
(
*
args
,
**
kwargs
):
if
hasattr
(
__local__
,
'db'
):
return
func
(
*
args
,
**
kwargs
)
with
Database
()
as
db
:
with
Database
(
config
)
as
db
:
__local__
.
db
=
db
try
:
result
=
func
(
*
args
,
**
kwargs
)
...
...
@@ -101,4 +102,8 @@ def transaction(func=None):
except
Exception
as
e
:
db
.
connect
.
rollback
()
raise
e
finally
:
del
__local__
.
db
return
wraps
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