Skip to content

Instantly share code, notes, and snippets.

@hashware
Last active June 21, 2018 14:17
Show Gist options
  • Save hashware/4b7c803ccfcf4b546eb28f04335d9844 to your computer and use it in GitHub Desktop.
Save hashware/4b7c803ccfcf4b546eb28f04335d9844 to your computer and use it in GitHub Desktop.

调用eos的get_block接口
获取块的json格式数据
将其导入MongoDB便于查询分析

#!/usr/bin/env python3
# coding:utf-8

import requests
import json
from pymongo import MongoClient

conn = MongoClient('127.0.0.1', 27017)
db = conn.eosdb
eosset = db.eosset

base_url = 'http://127.0.0.1:8888'
url = base_url + '/v1/chain/get_block'
blockid = 1
while True:
    print(blockid)
    payload = {'block_num_or_id': blockid, }
    r = requests.post(url, data=json.dumps(payload), timeout=20)
    j = json.loads(r.text)
    eosset.insert(j)
    blockid += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment