Skip to content

Commit 3367ae6

Browse files
author
Zoran Pandovski
committed
Import module, add core py, add url and version in setup
1 parent 74317e6 commit 3367ae6

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

pycoincap/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from core import CryptoMarket

pycoincap/core.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import requests
2+
3+
4+
class Coin(object):
5+
6+
def __init__(self,
7+
id = "",
8+
name = "",
9+
symbol = "",
10+
rank = "",
11+
price_usd = "",
12+
price_btc = "",
13+
market_cap_usd = "",
14+
available_supply = "",
15+
total_supply = "",
16+
percent_change_1h = "",
17+
percent_change_24h = "",
18+
percent_change_7d = "",
19+
last_updated = "",
20+
last_day_volume_usd=""):
21+
22+
self.id = id
23+
self.name = name
24+
self.symbol = symbol
25+
self.rank = rank
26+
self.price_usd = price_usd
27+
self.price_btc = price_btc
28+
self.market_cap_usd = market_cap_usd
29+
self.available_supply = available_supply
30+
self.total_supply = total_supply
31+
self.percent_change_1h = percent_change_1h
32+
self.percent_change_24h = percent_change_24h
33+
self.percent_change_7d = percent_change_7d
34+
self.last_updated = last_updated
35+
self.last_day_volume_usd = last_day_volume_usd
36+
37+
def __str__(self):
38+
info = "Coin: %s | Ranked: %s" % (self.name, self.rank)
39+
return info
40+
41+
def __repr__(self):
42+
return "Coin"
43+
44+
45+
class CryptoMarket(object):
46+
47+
__COIN_MARKET_CAP_URL = \
48+
'https://api.coinmarketcap.com/v1/'
49+
50+
def __call_market(self, endpoint, params):
51+
try:
52+
response = requests.get(
53+
self.__COIN_MARKET_CAP_URL + endpoint, params= params)
54+
if response.status_code != '200':
55+
response.raise_for_status()
56+
except requests.exceptions.HTTPError as e:
57+
raise e
58+
data = response.json()
59+
return data
60+
61+
def get_coin(self, name, **kwargs):
62+
params = {}
63+
params.update(**kwargs)
64+
data = self.__call_market(name, params)
65+
if 'error' in data:
66+
return 'Error occurred'
67+
coin = data[0]
68+
return Coin(coin['id'], coin['name'])

setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from setuptools import setup
1+
from distutils.core import setup
22

33
setup(
44
name='pycoincap',
5-
version='1.0',
5+
version='1.0.0',
6+
url = 'https://github.com/ZoranPandovski/pycoincap',
67
description='Module for getting cryptocurrency data from Coinmarketcap',
78
author='Zoran Pandovski',
89
author_email='[email protected]',
9-
url='https://github.com/anfederico/Stocktalk',
1010
packages=['pycoincap'],
11-
install_requires=['']
11+
install_requires=['requests']
1212
)

0 commit comments

Comments
 (0)