-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvsp.py
37 lines (31 loc) · 918 Bytes
/
vsp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
import pandas as pd
from datetime import date
import os
pd.set_option('display.max_columns', None)
url = 'https://api.decred.org/?c=vsp'
# get api response
response = requests.get(url)
data = response.json()
# convert to dataframe
df = pd.read_json(url)
# transpose
dft = df.T
# set the index label as id
dft.index.name = 'id'
# convert unix time to something readable
dft['launched'] = pd.to_datetime(dft['launched'],unit='s')
dft['lastupdated'] = pd.to_datetime(dft['lastupdated'],unit='s')
# check if path exists, if not create
if not os.path.exists('./data/vsp'):
os.makedirs('./data/vsp')
# get today's date for file path
todayStr = str(date.today())
yearMonthStr = date.today().strftime("%Y/%m/")
# path for raw data
pathStr = './data/vsp/' + yearMonthStr
if not os.path.exists(pathStr):
os.makedirs(pathStr)
filename = pathStr + todayStr + '.csv'
# save to csv
dft.to_csv(filename)