Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit ff413ea

Browse files
committed
Workaround for disabled CoinMarketCap API v2
- NEW: CoinMarketCap HTML scraper - MOD: Dropped CoinMarketCap API v2 - MOD: Bumped version from 0.1.2 to 0.1.3
1 parent cbdc4c1 commit ff413ea

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.2
1+
0.1.3

main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
import requests
44
from steem import Steem
55
from 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

722
def 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:

0 commit comments

Comments
 (0)