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

Commit

Permalink
Workaround for disabled CoinMarketCap API v2
Browse files Browse the repository at this point in the history
- NEW: CoinMarketCap HTML scraper
- MOD: Dropped CoinMarketCap API v2
- MOD: Bumped version from 0.1.2 to 0.1.3
  • Loading branch information
Deltik committed Mar 11, 2020
1 parent cbdc4c1 commit ff413ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3
21 changes: 19 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
import requests
from steem import Steem
from pprint import pprint
from html.parser import HTMLParser
import re

class CoinMarketCapPriceHTMLParser(HTMLParser):
next_data_is_price = False
raw_price = ''

def handle_starttag(self, tag, attrs):
if tag == 'span' and any(attr[1] == 'cmc-details-panel-price__price' for attr in attrs):
self.next_data_is_price = True

def handle_data(self, data):
if self.next_data_is_price:
self.raw_price = data
self.next_data_is_price = False

def main():
config = configparser.ConfigParser()
Expand All @@ -13,8 +28,10 @@ def main():
witness_name = config['steem-secrets']['witness_name']
wallet_password = config['steem-secrets']['wallet_password']

result = requests.get('https://api.coinmarketcap.com/v2/ticker/1230/?convert=USD')
price = result.json()['data']['quotes']['USD']['price']
result = requests.get('https://coinmarketcap.com/currencies/steem/')
parser = CoinMarketCapPriceHTMLParser()
parser.feed(result.text)
price = re.sub(r'[\$,]', '', parser.raw_price)
try:
price = float(price)
except ValueError:
Expand Down

0 comments on commit ff413ea

Please sign in to comment.