-
-
Save danielchalef/77d1361a52c7ae4e5f9e6f4e2459c914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
import re | |
import pandas as pd | |
import ast | |
tokenre = r"t=(\d+)" | |
soup = BeautifulSoup(requests.get("http://www.coinwarz.com/difficulty-charts/zcash-difficulty-chart").content, "html.parser") | |
script = soup.find("script", text=re.compile("getJSON")).text | |
token = re.findall(tokenre, script)[0] | |
r = requests.get("http://www.coinwarz.com/ajax/diffchartdata?coinId=439&t={}".format(token)) | |
vals = ast.literal_eval(r.content.decode('utf8')) | |
df = pd.DataFrame(vals) | |
df.index = pd.to_datetime(df[0], unit='ms') | |
df.index.name = 'time' | |
del df[0] | |
df.columns = ['difficulty'] | |
# Datapoints are hourly | |
df['ma6'] = df['difficulty'].rolling(window=6,center=False).mean() | |
df['ma24'] = df['difficulty'].rolling(window=24,center=False).mean() | |
df['ma96'] = df['difficulty'].rolling(window=96,center=False).mean() | |
# plot dataset | |
df.plot(figsize=(15,8)) | |
# plot last 30 days | |
df.loc[df.last_valid_index() - pd.Timedelta(days=30):].plot(figsize=(15,8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment