This repository was archived by the owner on Jun 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 0.1.2
1+ 0.1.3
Original file line number Diff line number Diff line change 33import requests
44from steem import Steem
55from pprint import pprint
6+ from html .parser import HTMLParser
7+ import re
8+
9+ class CoinMarketCapPriceHTMLParser (HTMLParser ):
10+ next_data_is_price = False
11+ raw_price = ''
12+
13+ def handle_starttag (self , tag , attrs ):
14+ if tag == 'span' and any (attr [1 ] == 'cmc-details-panel-price__price' for attr in attrs ):
15+ self .next_data_is_price = True
16+
17+ def handle_data (self , data ):
18+ if self .next_data_is_price :
19+ self .raw_price = data
20+ self .next_data_is_price = False
621
722def main ():
823 config = configparser .ConfigParser ()
@@ -13,8 +28,10 @@ def main():
1328 witness_name = config ['steem-secrets' ]['witness_name' ]
1429 wallet_password = config ['steem-secrets' ]['wallet_password' ]
1530
16- result = requests .get ('https://api.coinmarketcap.com/v2/ticker/1230/?convert=USD' )
17- price = result .json ()['data' ]['quotes' ]['USD' ]['price' ]
31+ result = requests .get ('https://coinmarketcap.com/currencies/steem/' )
32+ parser = CoinMarketCapPriceHTMLParser ()
33+ parser .feed (result .text )
34+ price = re .sub (r'[\$,]' , '' , parser .raw_price )
1835 try :
1936 price = float (price )
2037 except ValueError :
You can’t perform that action at this time.
0 commit comments