Skip to content

Commit

Permalink
First version of cryptobalances package. Currently only supports two …
Browse files Browse the repository at this point in the history
…currencies: BTC and LTC
  • Loading branch information
AleksandrLeonov committed Jan 27, 2017
1 parent 9fc956b commit 8eb4cae
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Package build
/dist/*
/cryptobalances.egg-info/*
cryptobalances/__pycache__/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Crypto-Balances
Python module for getting balance of varios crypto currency
Python module for getting the balance of a various crypto currency.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Description
===========
A module for getting the balance of wallet for various crypto currency.
2 changes: 2 additions & 0 deletions cryptobalances/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .checker import get_balance
__version__ = '0.9'
36 changes: 36 additions & 0 deletions cryptobalances/checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
import json
import argparse
from urllib.request import urlopen
from urllib.error import URLError, HTTPError


def get_balance(currency, identifier):
api_url = {'ETH': 'http://api.etherscan.io/api?module=account&action=balance&address={identifier}&tag=latest',
'BTC': 'https://chain.so/api/v2/get_address_balance/{network}/{identifier}',
'LTC': 'https://chain.so/api/v2/get_address_balance/{network}/{identifier}',
'DOGE': 'http://dogechain.info/api/v1/address/balance/{identifier}',
'XCP': 'http://xcp.blockscan.com/api2?module=address&action=balance&btc_address={identifier}'}
try:
with urlopen(api_url[currency].format(network=currency, identifier=identifier), timeout=60) as f:
return json.loads(f.read().decode('utf-8'))['data']['confirmed_balance']
except HTTPError as error:
response = json.loads(error.read().decode('utf-8'))
print("{}. {}".format(response['data']['network'], response['data']['address']))
except URLError as error:
print(error.reason)
except (ValueError, KeyError) as error:
print(error)


def main():
parser = argparse.ArgumentParser(description='Getting balance of wallet of your crypto currency')
parser.add_argument('currency', nargs='?', type=str, help='Type of currency')
parser.add_argument('wallet', nargs='?', type=str, help='Identifier of wallet')
args = parser.parse_args()
if (args.currency and args.wallet) is not None:
print(get_balance(args.currency, args.wallet))


if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import cryptobalances
from setuptools import setup, find_packages
from os.path import join, dirname


setup(
name='cryptobalances',
version=cryptobalances.__version__,
author='Aliaksandr Leonau',
author_email='[email protected]',
packages=find_packages(),
description='Python module for getting the balance of a various crypto currency',
long_description=open(join(dirname(__file__), 'README.rst')).read(),
url='https://github.com',
platforms='Linux',
)

0 comments on commit 8eb4cae

Please sign in to comment.