Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
df-aggregator
Overview
Overview
Details
Activity
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
Oleksandr Barabash
df-aggregator
Commits
ca3b28c9
Commit
ca3b28c9
authored
Jun 17, 2023
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
absl added
parent
08410532
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
30 deletions
+21
-30
app.py
app.py
+21
-30
No files found.
app.py
View file @
ca3b28c9
...
...
@@ -6,7 +6,8 @@ import sys
from
asyncio
import
AbstractEventLoop
from
typing
import
Optional
import
numpy
as
np
from
absl
import
app
,
flags
from
absl.flags
import
FLAGS
from
marshmallow
import
EXCLUDE
from
utils.ether_service.entities.data.kr_packet
import
KrPacketV2
...
...
@@ -17,6 +18,10 @@ from utils.ws_client import WSClient
logger
=
logging
.
getLogger
(
__name__
)
flags
.
DEFINE_string
(
'station_id'
,
None
,
"Station_id"
)
flags
.
DEFINE_string
(
'file_name'
,
None
,
"File where to save the history"
)
def
init_logging
(
filename
=
None
,
level
=
None
):
""" init logging on the app level """
logging_config
=
{
"format"
:
"
%(message)
s"
,
...
...
@@ -50,12 +55,7 @@ def try_to_log(kr_packet: KrPacketV2,
logging
.
error
(
"save to file error!"
,
exc_info
=
sys
.
exc_info
())
# noinspection PyShadowingNames
def
handle_message
(
station_name
:
Optional
[
str
]
=
None
,
log_name
:
Optional
[
str
]
=
None
)
->
"(_: bytes) -> None"
:
""" Handle Message """
def
wrapped
(
data
:
bytes
)
->
None
:
def
handle_message
(
data
:
bytes
)
->
None
:
""" Handle Message """
message
=
json_loads
(
data
)
if
message
is
None
:
...
...
@@ -65,26 +65,29 @@ def handle_message(station_name: Optional[str] = None,
# noinspection PyBroadException
try
:
kr_packet
=
KrPacketV2
.
load
(
message
,
unknown
=
EXCLUDE
)
if
station_name
is
None
or
\
station_name
.
lower
()
==
kr_packet
.
station_id
.
lower
():
station_id
=
FLAGS
.
station_id
if
station_id
is
None
or
\
station_id
.
lower
()
==
kr_packet
.
station_id
.
lower
():
logging
.
info
(
f
"{kr_packet}"
)
try_to_log
(
kr_packet
,
log_name
)
try_to_log
(
kr_packet
)
except
Exception
:
logging
.
error
(
"handle_message: Error!"
,
exc_info
=
sys
.
exc_info
())
return
wrapped
# noinspection PyShadowingNames
def
main
(
io_loop
:
AbstractEventLoop
,
station_name
:
Optional
[
str
]
=
None
,
log_name
:
Optional
[
str
]
=
None
)
->
None
:
def
main
(
argv
)
->
None
:
""" Main """
logging
.
getLogger
(
"geventwebsocket"
)
.
level
=
logging
.
WARNING
logging
.
getLogger
(
"asyncio"
)
.
level
=
logging
.
INFO
logging_level
=
logging
.
INFO
init_logging
(
level
=
logging_level
)
io_loop
=
asyncio
.
get_event_loop
()
ws_client
=
WSClient
(
io_loop
=
io_loop
,
scheme
=
"https"
,
host
=
"cds.s1z.info"
,
path
=
"/api/v1/ws-agg"
,
user
=
"kraken"
,
password
=
"kraken"
,
ca_file
=
"./ca.pem"
,
on_data_handler
=
handle_message
(
station_name
,
log_name
))
on_data_handler
=
handle_message
)
ws_client
.
start
()
signal
.
signal
(
signal
.
SIGINT
,
stop_server
(
ws_client
,
io_loop
))
signal
.
signal
(
signal
.
SIGTERM
,
stop_server
(
ws_client
,
io_loop
))
...
...
@@ -92,16 +95,4 @@ def main(io_loop: AbstractEventLoop,
if
__name__
==
"__main__"
:
logging
.
getLogger
(
"geventwebsocket"
)
.
level
=
logging
.
WARNING
logging
.
getLogger
(
"asyncio"
)
.
level
=
logging
.
INFO
logging_level
=
logging
.
INFO
init_logging
(
level
=
logging_level
)
loop
=
asyncio
.
get_event_loop
()
station_name
,
file_name
=
None
,
None
if
len
(
sys
.
argv
)
>
1
:
station_name
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
2
:
file_name
=
sys
.
argv
[
2
]
main
(
loop
,
station_name
,
file_name
)
app
.
run
(
main
)
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