Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PyFund
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
陈涛
PyFund
Commits
5ba58040
Commit
5ba58040
authored
Jun 21, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改解析beacon
parent
0d260465
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
16 deletions
+19
-16
fund.py
model/fund.py
+2
-1
beacon.py
service/beacon.py
+17
-15
No files found.
model/fund.py
View file @
5ba58040
...
...
@@ -52,4 +52,5 @@ class StakingFundNav(StakingFund):
record_date
:
datetime
.
datetime
=
Field
(
default_factory
=
lambda
:
datetime
.
datetime
.
utcnow
()
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
,
microsecond
=
0
,
tzinfo
=
pytz
.
UTC
),
description
=
"记录时间"
)
\ No newline at end of file
)
node_income_assets
:
Dict
[
str
,
float
]
=
Field
(
default
=
{},
description
=
'质押资产'
)
\ No newline at end of file
service/beacon.py
View file @
5ba58040
...
...
@@ -174,29 +174,31 @@ class BeaconChaService:
return
eval
(
re
.
findall
(
r'var executionIncomeHistory = \[(.*?)\]'
,
response
.
text
)[
0
])
def
get_rewards
(
self
,
index_or_pubkey
:
Union
[
int
,
str
])
->
Rewards
:
total_reward_element_path
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td/span"
total_reward_element_text_path
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td/span"
income_today_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[2]/td/span"
income_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span"
income_today_total_path
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[2]/td/span/span"
total_income1d_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span/span[1]"
total_income7d_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span/span[2]"
total_income365d_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span/span[3]"
response
=
requests
.
get
(
f
"{self.base_url}/validator/{index_or_pubkey}"
)
html
=
response
.
content
# 解析 HTML 页面
tree
=
etree
.
HTML
(
html
)
total_rewards_re
=
tree
.
xpath
(
'/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td/span'
)[
0
]
total_rewards_re
=
tree
.
xpath
(
total_reward_element_path
)[
0
]
total_rewards_title
=
total_rewards_re
.
get
(
"title"
)
total_list
=
re
.
findall
(
r'<span>(.?\d+\.?\d*) ETH</span>'
,
total_rewards_title
)
total_total_rewards_text
=
tree
.
xpath
(
'/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td/span/b'
)[
0
]
.
text
total_total_rewards
=
re
.
findall
(
r"
.?\d+\.?\d*
"
,
total_total_rewards_text
)[
0
]
total_list
=
re
.
findall
(
r'<span>(.?\d+\.?\d*) ETH</span>'
,
total_rewards_title
)
if
total_rewards_title
else
[
0
,
0
]
total_total_rewards_text
=
etree
.
tostring
(
tree
.
xpath
(
total_reward_element_text_path
)[
0
],
encoding
=
'unicode'
)
total_total_rewards
=
re
.
findall
(
r"
>(.?\d+\.?\d*)
"
,
total_total_rewards_text
)[
0
]
# income_today
income_today_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[2]/td/span"
income_today_total_path
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[2]/td/span/span/b"
income_today_re
,
total_income_today
=
tree
.
xpath
(
income_today_xpath
)[
0
],
tree
.
xpath
(
income_today_total_path
)[
0
]
.
text
income_today_re
,
total_income_today
=
tree
.
xpath
(
income_today_xpath
)[
0
],
etree
.
tostring
(
tree
.
xpath
(
income_today_total_path
)[
0
],
encoding
=
'unicode'
)
income_today_list
=
re
.
findall
(
r"(.?\d+\.?\d*) ETH"
,
income_today_re
.
get
(
"title"
))
total_income_today
=
re
.
findall
(
r"
.?\d+\.?\d*
"
,
total_income_today
)[
0
]
total_income_today
=
re
.
findall
(
r"
>(.?\d+\.?\d*)
"
,
total_income_today
)[
0
]
# income
total_income1d_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span/span[1]/b"
total_income7d_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span/span[2]/b"
total_income365d_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span/span[3]/b"
total_income1d
=
re
.
findall
(
r".?\d+\.?\d*"
,
tree
.
xpath
(
total_income1d_xpath
)[
0
]
.
text
)[
0
]
total_income7d
=
re
.
findall
(
r".?\d+\.?\d*"
,
tree
.
xpath
(
total_income7d_xpath
)[
0
]
.
text
)[
0
]
total_income31d
=
re
.
findall
(
r".?\d+\.?\d*"
,
tree
.
xpath
(
total_income365d_xpath
)[
0
]
.
text
)[
0
]
income_xpath
=
"/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[3]/td/span"
total_income1d
=
re
.
findall
(
r">(.?\d+\.?\d*)"
,
etree
.
tostring
(
tree
.
xpath
(
total_income1d_xpath
)[
0
],
encoding
=
'unicode'
))[
0
]
total_income7d
=
re
.
findall
(
r">(.?\d+\.?\d*)"
,
etree
.
tostring
(
tree
.
xpath
(
total_income7d_xpath
)[
0
],
encoding
=
'unicode'
))[
0
]
total_income31d
=
re
.
findall
(
r">(.?\d+\.?\d*)"
,
etree
.
tostring
(
tree
.
xpath
(
total_income365d_xpath
)[
0
],
encoding
=
'unicode'
))[
0
]
income_list
=
re
.
findall
(
r".?\d+\.?\d*"
,
tree
.
xpath
(
income_xpath
)[
0
]
.
get
(
"title"
))
result
=
Rewards
(
total_rewards
=
NodeGeneral
(
cl
=
float
(
total_list
[
0
]),
el
=
float
(
total_list
[
1
]),
total
=
float
(
total_total_rewards
)),
...
...
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