Skip to content

Instantly share code, notes, and snippets.

@xeroc
Created April 10, 2018 15:37
Show Gist options
  • Save xeroc/fdcb3bb6f13ef1d78e57018d2811fb4b to your computer and use it in GitHub Desktop.
Save xeroc/fdcb3bb6f13ef1d78e57018d2811fb4b to your computer and use it in GitHub Desktop.
from pprint import pprint
from datetime import datetime
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
from bitshares.account import Account
from bitshares.blockchainobject import BlockchainObject
from bitshares.instance import shared_bitshares_instance
class ES:
def __init__(self, *args, **kwargs):
self.es = Elasticsearch(
*kwargs.get("esargs", []),
**kwargs.get("eskwargs", {})
)
class AccountHistory(dict, ES):
def __init__(self, account, *args, bitshares_instance=None, **kwargs):
self.bitshares = bitshares_instance or shared_bitshares_instance()
self.account = Account(account, bitshares_instance=self.bitshares)
ES.__init__(self, *args, **kwargs)
self.search = Search(using=self.es, index="graphene-*") \
.query("match", account_history__account=self.account["id"])
def query(self, *args, **kwargs):
return self.search.query(*args, **kwargs)
def history(self, operation_id=None):
q = self.search
if operation_id:
q = q.query("match", operation_type=operation_id)
q.execute()
for x in q.scan():
yield x.to_dict()
@property
def total(self):
return self.count()
def count(self):
return self.search.count()
a = AccountHistory(
"xeroc",
esargs=[["176.9.44.67"]],
)
for h in a.history(0):
pprint(h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment