-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn_range_blocks.py
More file actions
45 lines (37 loc) · 1.12 KB
/
return_range_blocks.py
File metadata and controls
45 lines (37 loc) · 1.12 KB
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
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 15 14:26:43 2019
@author: washington.zanoni
Descrição:
Esse código busca/retorna blocos especificando uma faixa de números dos blocos.
É necessario criar pastas em seu computador
Fonte:
https://blockchain.info
End-point:
https://blockchain.info/block-height/{numero-bloco}?format=json
"""
import requests
import pandas as pd
import json
from pandas.io.json import json_normalize
from IPython.display import display
# crie diretórios/arquivo c:/blockchain/upblocks_range/
path_json = 'C:/blockchain/upblocks_range/'
cont_block = 3
i=0
print('Start....')
while i <= cont_block:
try:
url = 'https://blockchain.info/block-height/'+str(i)+'?format=json'
arq_json = requests.get(url).json()
with open(path_json+str(i)+'blocks.json', 'w') as json_file:
json.dump(arq_json, json_file)
json_file.close()
print(i)
i=i+1
time.sleep(10)
except Except as e:
i=i-1
print('erro', i , ' /n', e)
pass
print('End...')