-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethplorer.py
41 lines (26 loc) · 927 Bytes
/
ethplorer.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
38
39
# coding: utf-8
# In[ ]:
# Program: ethplorer.py
# Ethplorer holders data fetch
# Output write CSV file named optput.csv
# Author: Kevin Liu
# Date: 2018-09-30
# Ver: 0.3
import requests
import json
import csv
res = requests.get('https://ethplorer.io/service/service.php?refresh=holders&data=0x503F9794d6A6bB0Df8FBb19a2b3e2Aeab35339Ad&page=tab%3Dtab-holders%26pageSize%3D49999&showTx=all')
if res.status_code == 200:
data = json.loads(res.text)
print('Success get data.')
# Write JSON to CSV
with open('output.csv', 'w', newline='') as csvfile:
fieldnames = ['address', 'balance', 'share']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for csvline in data['holders']:
writer.writerow(csvline)
print('CSV output success.')
csvfile.close
else:
print('Connection server fail.')